pub struct Id { /* private fields */ }Expand description
This is the Id type, that uniquely identifies slices of bytes,
in rust equivalent to &[u8]. As in the case with &[u8] the length is
also encoded in the type, making it a kind of a fat-pointer for content
addressed byte-slices.
The length of the corresponding byte-string is encoded in the first two bytes in big endian.
If the length of the byteslice is less than or equal to 32 bytes, the bytes
are stored directly inline in the bytes field.
Proposal: The trailing bytes in an inlined value MUST be set to zero
Implementations§
Source§impl Id
impl Id
Sourcepub fn hash(&self) -> IdHash
pub fn hash(&self) -> IdHash
Returns the computed hash of the value.
Note that this is different from the payload itself in case of an inlined value, that normally does not get hashed.
Useful for giving a well-distributed unique id for all Canon types,
for use in hash maps for example.
Sourcepub fn reify<T>(&self) -> Result<T, CanonError>where
T: Canon,
pub fn reify<T>(&self) -> Result<T, CanonError>where
T: Canon,
Attempts to reify the Id as an instance of type T
Sourcepub fn take_bytes(&self) -> Result<Option<Vec<u8>>, CanonError>
pub fn take_bytes(&self) -> Result<Option<Vec<u8>>, CanonError>
Takes the bytes corresponding to this id out of the underlying store.
If the Id is inlined, this is a no-op and returns Ok(None)
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Id
impl<'a> Arbitrary<'a> for Id
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read more