Struct git_repository::oid
source · [−]#[repr(transparent)]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 additinoal 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()][oid::kind()]
.
We expect to have quite a few bits available for such ‘conflict resolution’ as most hashes aren’t longer
than 64 bytes.
Implementations
sourceimpl oid
impl oid
Conversion
sourcepub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
pub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
Try to create a shared object id from a slice of bytes representing a hash digest
sourcepub fn from_bytes_unchecked(value: &[u8]) -> &oid
pub fn from_bytes_unchecked(value: &[u8]) -> &oid
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.
sourceimpl oid
impl oid
Access
sourcepub fn first_byte(&self) -> u8
pub fn first_byte(&self) -> u8
The first byte of the hash, commonly used to partition a set of Id
s
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Interpret this object id as raw byte slice.
sourcepub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
pub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
Return a type which can display itself in hexadecimal form with the len
amount of characters.
Trait Implementations
sourceimpl Ord for oid
impl Ord for oid
sourceimpl PartialOrd<oid> for oid
impl PartialOrd<oid> for oid
sourcefn partial_cmp(&self, other: &oid) -> Option<Ordering>
fn partial_cmp(&self, other: &oid) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more