Skip to content

Commit

Permalink
Update rustler and xxhash-rust to latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Farhadi committed Nov 19, 2024
1 parent 17631b5 commit 77b230d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:

strategy:
matrix:
otp: [21, 22, 23, 24, 25, 26]
rust: [1.56.0, stable]
otp: [21, 22, 23, 24, 25, 26, 27]
rust: [1.72.0, stable, nightly]

container:
image: erlang:${{matrix.otp}}
Expand Down
File renamed without changes.
155 changes: 93 additions & 62 deletions native/xxh3/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions native/xxh3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xxh3"
version = "0.3.5"
version = "0.3.6"
authors = []
edition = "2018"

Expand All @@ -10,5 +10,5 @@ path = "src/lib.rs"
crate-type = ["dylib"]

[dependencies]
rustler = "0.29.1"
xxhash-rust = { version = "0.8.6", features = ["xxh3"] }
rustler = "0.35.0"
xxhash-rust = { version = "0.8.12", features = ["xxh3"] }
53 changes: 13 additions & 40 deletions native/xxh3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,48 @@
use rustler::resource::ResourceArc;
use rustler::types::atom::{self, Atom};
use rustler::types::binary::{Binary, OwnedBinary};
use rustler::{Env, Error, Term};
use rustler::{Error, Resource, ResourceArc};
use std::convert::TryInto;
use std::io::Write;
use std::sync::Mutex;
use xxhash_rust::xxh3::{self, Xxh3};

struct Xxh3Resource {
pub stream: Mutex<Xxh3>,
}
struct Xxh3Resource(Mutex<Xxh3>);

fn on_load(env: Env, _info: Term) -> bool {
rustler::resource!(Xxh3Resource, env);
true
}
#[rustler::resource_impl]
impl Resource for Xxh3Resource {}

#[rustler::nif]
fn new() -> ResourceArc<Xxh3Resource> {
ResourceArc::new(Xxh3Resource {
stream: Mutex::new(Xxh3::new()),
})
ResourceArc::new(Xxh3Resource(Mutex::new(Xxh3::new())))
}

#[rustler::nif(name = "new")]
fn new_with_seed(seed: u64) -> ResourceArc<Xxh3Resource> {
ResourceArc::new(Xxh3Resource {
stream: Mutex::new(Xxh3::with_seed(seed)),
})
ResourceArc::new(Xxh3Resource(Mutex::new(Xxh3::with_seed(seed))))
}

#[rustler::nif]
fn new_with_secret(secret: Binary) -> Result<ResourceArc<Xxh3Resource>, Error> {
Ok(ResourceArc::new(Xxh3Resource {
stream: Mutex::new(Xxh3::with_secret(
secret.as_slice().try_into().map_err(|_| Error::BadArg)?,
)),
}))
Ok(ResourceArc::new(Xxh3Resource(Mutex::new(
Xxh3::with_secret(secret.as_slice().try_into().map_err(|_| Error::BadArg)?),
))))
}

#[rustler::nif]
fn update(resource: ResourceArc<Xxh3Resource>, data: Binary) -> Atom {
resource.stream.try_lock().unwrap().update(data.as_slice());
resource.0.lock().unwrap().update(data.as_slice());
atom::ok()
}

#[rustler::nif]
fn reset(resource: ResourceArc<Xxh3Resource>) -> Atom {
resource.stream.try_lock().unwrap().reset();
resource.0.lock().unwrap().reset();
atom::ok()
}

#[rustler::nif]
fn digest(resource: ResourceArc<Xxh3Resource>) -> u64 {
resource.stream.try_lock().unwrap().digest()
resource.0.lock().unwrap().digest()
}

#[rustler::nif]
Expand Down Expand Up @@ -87,20 +76,4 @@ fn hash128_with_secret_bin(data: Binary, secret: Binary) -> OwnedBinary {
binary
}

rustler::init!(
"xxh3",
[
new,
new_with_seed,
new_with_secret,
update,
reset,
digest,
hash64,
hash64_with_seed,
hash64_with_secret,
hash128_with_seed_bin,
hash128_with_secret_bin
],
load = on_load
);
rustler::init!("xxh3");
2 changes: 1 addition & 1 deletion src/xxh3.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, xxh3, [
{description, "NIF bindings for XXH3 hash functions implemented in Rust"},
{vsn, "0.3.5"},
{vsn, "0.3.6"},
{registered, []},
{applications, [
kernel,
Expand Down

0 comments on commit 77b230d

Please sign in to comment.