pub trait RHash {
// Required method
fn r_hash(&self) -> String;
// Provided method
#[doc(hidden)] unsafe extern "C" fn __RHash_r_hash_shim(
data: *mut c_void,
argc: i32,
argv: *const SEXP,
) -> SEXP
where Self: Sized + RHash { ... }
}Expand description
Adapter trait for std::hash::Hash.
Provides hashing for deduplication and environment keys in R.
Automatically implemented for any type that implements Hash.
§Methods
r_hash()(hash()in R) - Returns the 64-bit hash as a 16-character hex string
§Note
Hash values are deterministic within a single R session but may vary between sessions due to Rust’s hasher implementation.
The hash is returned as a hex String (e.g. "a1b2c3d4e5f60718"), not a
number. R has no faithful 64-bit integer type, so returning the u64 as a
numeric would round away its low bits above 2^53 — distinct Rust values
would collide in R — and surface half the range as negative. A hex string
preserves all 64 bits, is directly usable as an R environment key, and
works with duplicated() / match() for deduplication.
§Example
#[derive(Hash, ExternalPtr)]
struct Record { id: String, value: i64 }
#[miniextendr]
impl miniextendr_api::adapter_traits::RHash for Record {}Required Methods§
Sourcefn r_hash(&self) -> String
fn r_hash(&self) -> String
Compute a hash of this value.
Returns the DefaultHasher u64 output as a 16-character lowercase
hex string. See the trait-level docs for why a string rather than a
number.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".