#[non_exhaustive]pub enum ObjectId {
Sha1([u8; 20]),
Sha256([u8; 32]),
}Expand description
An owned hash identifying objects, most commonly Sha1
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Sha1([u8; 20])
sha1 only.A SHA1 hash digest
Sha256([u8; 32])
sha256 only.A SHA256 hash digest
Implementations§
Source§impl ObjectId
Hash decoding
impl ObjectId
Hash decoding
Sourcepub fn from_hex(buffer: &[u8]) -> Result<ObjectId, Error>
pub fn from_hex(buffer: &[u8]) -> Result<ObjectId, Error>
Create an instance from a buffer of 40 bytes or 64 bytes encoded with hexadecimal
notation. The former will be interpreted as SHA1 while the latter will be interpreted
as SHA256 when it is enabled.
Such a buffer can be obtained using oid::write_hex_to(buffer)
Source§impl ObjectId
Access and conversion
impl ObjectId
Access and conversion
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Return the raw mutable byte slice representing this hash.
Sourcepub const fn empty_blob(hash: Kind) -> ObjectId
pub const fn empty_blob(hash: Kind) -> ObjectId
The hash of an empty blob.
Sourcepub const fn empty_tree(hash: Kind) -> ObjectId
pub const fn empty_tree(hash: Kind) -> ObjectId
The hash of an empty tree.
Sourcepub fn is_empty_blob(&self) -> bool
pub fn is_empty_blob(&self) -> bool
Returns true if this hash is equal to an empty blob.
Sourcepub fn is_empty_tree(&self) -> bool
pub fn is_empty_tree(&self) -> bool
Returns true if this hash is equal to an empty tree.
Methods from Deref<Target = oid>§
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 object ids.
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.
Sourcepub fn to_prefix(&self, range: Range<usize>) -> Prefix
pub fn to_prefix(&self, range: Range<usize>) -> Prefix
Return the bytes in range as a standalone, byte-aligned Prefix.
The range addresses raw hash bytes, not hexadecimal digits. Thus, each selected byte contributes two hexadecimal digits to the returned prefix. The selected bytes become the beginning of the prefix, independently of where they occurred in this object ID.
§Panics
If range is out of bounds or has its start after its end.
Sourcepub fn hex_to_buf<'a>(&self, buf: &'a mut [u8]) -> &'a mut str
pub fn hex_to_buf<'a>(&self, buf: &'a mut [u8]) -> &'a mut str
Write ourselves to the out in hexadecimal notation, returning the hex-string ready for display.
§Panics
If the buffer isn’t big enough to hold twice as many bytes as the current binary size.
Sourcepub fn write_hex_to(&self, out: &mut dyn Write) -> Result<()>
pub fn write_hex_to(&self, out: &mut dyn Write) -> Result<()>
Write ourselves to out in hexadecimal notation.
Sourcepub fn is_empty_blob(&self) -> bool
pub fn is_empty_blob(&self) -> bool
Returns true if this hash is equal to an empty blob.
Sourcepub fn is_empty_tree(&self) -> bool
pub fn is_empty_tree(&self) -> bool
Returns true if this hash is equal to an empty tree.
Trait Implementations§
impl Copy for ObjectId
Source§impl<'de> Deserialize<'de> for ObjectId
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ObjectId
serde only.