pub struct Reference(/* private fields */);
Expand description
A globally unique reference to a globally unique object.
Reference
provides a cryptographically secure way to uniquely identify
objects based on their content. It is a fixed-size (32 bytes) identifier,
typically derived from the SHA-256 hash of the object’s serialized form.
References are useful in distributed systems for:
- Unique identification of objects across networks
- Verification that an object hasn’t been modified
- Content-addressable storage systems
- Linking between objects in a content-addressed way
A Reference
can be displayed in various formats, including hexadecimal,
ByteWords (a human-readable partial hash as words), and Bytemoji (a
human-readable partial hash based on emojis).
Implementations§
Source§impl Reference
impl Reference
pub const REFERENCE_SIZE: usize = 32usize
Sourcepub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
pub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
Create a new reference from data.
Returns None
if the data is not the correct length.
Sourcepub fn from_digest(digest: Digest) -> Self
pub fn from_digest(digest: Digest) -> Self
Create a new reference from the given digest.
Sourcepub fn from_hex(hex: impl AsRef<str>) -> Self
pub fn from_hex(hex: impl AsRef<str>) -> Self
Create a new reference from the given hexadecimal string.
§Panics
Panics if the string is not exactly 64 hexadecimal digits.
Sourcepub fn ref_data_short(&self) -> [u8; 4]
pub fn ref_data_short(&self) -> [u8; 4]
The first four bytes of the reference
Sourcepub fn ref_hex_short(&self) -> String
pub fn ref_hex_short(&self) -> String
The first four bytes of the reference as a hexadecimal string.
Sourcepub fn bytewords_identifier(&self, prefix: Option<&str>) -> String
pub fn bytewords_identifier(&self, prefix: Option<&str>) -> String
The first four bytes of the XID as upper-case ByteWords.
Sourcepub fn bytemoji_identifier(&self, prefix: Option<&str>) -> String
pub fn bytemoji_identifier(&self, prefix: Option<&str>) -> String
The first four bytes of the XID as Bytemoji.
Trait Implementations§
Source§impl CBORTagged for Reference
impl CBORTagged for Reference
Source§impl CBORTaggedDecodable for Reference
impl CBORTaggedDecodable for Reference
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for Reference
impl CBORTaggedEncodable for Reference
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl DigestProvider for Reference
impl DigestProvider for Reference
Source§impl Ord for Reference
impl Ord for Reference
Source§impl PartialOrd for Reference
impl PartialOrd for Reference
Source§impl ReferenceProvider for Reference
Implement the ReferenceProvider
trait for Reference
.
impl ReferenceProvider for Reference
Implement the ReferenceProvider
trait for Reference
.
Yes, this creates a Reference to a Reference.
Source§fn reference(&self) -> Reference
fn reference(&self) -> Reference
Source§fn ref_hex_short(&self) -> String
fn ref_hex_short(&self) -> String
impl Eq for Reference
impl StructuralPartialEq for Reference
Auto Trait Implementations§
impl Freeze for Reference
impl RefUnwindSafe for Reference
impl Send for Reference
impl Sync for Reference
impl Unpin for Reference
impl UnwindSafe for Reference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)