Skip to main content

RHash

Trait RHash 

Source
pub trait RHash {
    // Required method
    fn hash(&self) -> String;
}
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

  • hash() - 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 RHash for Record {}

Required Methods§

Source

fn 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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Hash> RHash for T