pub struct oid { /* private fields */ }Expand description
A borrowed reference to a hash identifying objects.
§Future Proofing
In case we wish to support multiple hashes with the same length we cannot discriminate
using the slice length anymore. To make that work, we will use the high bits of the
internal bytes slice length (a fat pointer, pointing to data and its length in bytes)
to encode additional information. Before accessing or returning the bytes, a new adjusted
slice will be constructed, while the high bits will be used to help resolving the
hash kind().
We expect to have quite a few bits available for such ‘conflict resolution’ as most hashes aren’t longer
than 64 bytes.
Implementations§
source§impl oid
impl oid
Conversion
sourcepub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
Available on crate feature index only.
pub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
index only.Try to create a shared object id from a slice of bytes representing a hash digest
sourcepub fn from_bytes_unchecked(value: &[u8]) -> &oid
Available on crate feature index only.
pub fn from_bytes_unchecked(value: &[u8]) -> &oid
index only.Create an OID from the input value slice without performing any safety check.
Use only once sure that value is a hash of valid length.
source§impl oid
impl oid
Access
sourcepub fn kind(&self) -> Kind
Available on crate feature index only.
pub fn kind(&self) -> Kind
index only.The kind of hash used for this instance.
sourcepub fn first_byte(&self) -> u8
Available on crate feature index only.
pub fn first_byte(&self) -> u8
index only.The first byte of the hash, commonly used to partition a set of object ids.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
Available on crate feature index only.
pub fn as_bytes(&self) -> &[u8] ⓘ
index only.Interpret this object id as raw byte slice.
sourcepub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
Available on crate feature index only.
pub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
index only.Return a type which can display itself in hexadecimal form with the len amount of characters.
source§impl oid
impl oid
Sha1 specific methods
sourcepub fn hex_to_buf(&self, buf: &mut [u8]) -> usize
Available on crate feature index only.
pub fn hex_to_buf(&self, buf: &mut [u8]) -> usize
index only.Write ourselves to the out in hexadecimal notation, returning the amount of written bytes.
Panics if the buffer isn’t big enough to hold twice as many bytes as the current binary size.
Trait Implementations§
source§impl<'de, 'a> Deserialize<'de> for &'a oidwhere
'de: 'a,
Available on crate feature serde only.
impl<'de, 'a> Deserialize<'de> for &'a oidwhere
'de: 'a,
serde only.Manually created from a version that uses a slice, and we forcefully try to convert it into a borrowed array of the desired size
Could be improved by fitting this into serde.
Unfortunately the serde::Deserialize derive wouldn’t work for borrowed arrays.
source§fn deserialize<D>(
deserializer: D
) -> Result<&'a oid, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<&'a oid, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl PartialEq<&oid> for ObjectId
impl PartialEq<&oid> for ObjectId
source§impl PartialEq<ObjectId> for &oid
impl PartialEq<ObjectId> for &oid
source§impl PartialOrd for oid
impl PartialOrd for oid
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more