From 317eabc4eb6052d8447f0ce6a61a1c39b00671dc Mon Sep 17 00:00:00 2001 From: Ginger Date: Fri, 23 Jan 2026 14:18:19 -0500 Subject: [PATCH] feat: Add arbit utility module --- Cargo.lock | 7 +++++++ Cargo.toml | 4 ++++ src/core/Cargo.toml | 1 + src/core/utils/arbit.rs | 13 +++++++++++++ src/core/utils/mod.rs | 1 + 5 files changed, 26 insertions(+) create mode 100644 src/core/utils/arbit.rs diff --git a/Cargo.lock b/Cargo.lock index 34847a6f2..62dc11413 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1123,6 +1123,7 @@ dependencies = [ "ctor", "cyborgtime", "either", + "fastrand", "figment", "futures", "hardened_malloc-rs", @@ -1921,6 +1922,12 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "fax" version = "0.2.6" diff --git a/Cargo.toml b/Cargo.toml index 30e110948..fc4143d42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,10 @@ version = "0.1.3" [workspace.dependencies.rand] version = "0.8.5" +# used for stamps +[workspace.dependencies.fastrand] +version = "2.3.0" + # Used for the http request / response body type for Ruma endpoints used with reqwest [workspace.dependencies.bytes] version = "1.10.1" diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 8139f2d3e..4c75f5af2 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -71,6 +71,7 @@ core_affinity.workspace = true ctor.workspace = true cyborgtime.workspace = true either.workspace = true +fastrand.workspace = true figment.workspace = true futures.workspace = true http-body-util.workspace = true diff --git a/src/core/utils/arbit.rs b/src/core/utils/arbit.rs new file mode 100644 index 000000000..36ef28c63 --- /dev/null +++ b/src/core/utils/arbit.rs @@ -0,0 +1,13 @@ +pub const ARBIT_LENGTH: usize = 32; +/// An arbit is an opaque, random 32-byte identifier. +/// They are useful as unique, unordered database keys with no particular +/// semantics except uniqueness. +pub type Arbit = [u8; ARBIT_LENGTH]; + +#[must_use] +#[inline] +pub fn arbit() -> Arbit { + let mut arbit = [0; ARBIT_LENGTH]; + fastrand::fill(&mut arbit); + arbit +} diff --git a/src/core/utils/mod.rs b/src/core/utils/mod.rs index be7ccb19a..377347d1b 100644 --- a/src/core/utils/mod.rs +++ b/src/core/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod arbit; pub mod arrayvec; pub mod bool; pub mod bytes;