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
Conversion
impl oid
Conversion
Sourcepub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
Available on crate feature excludes only.
pub fn try_from_bytes(digest: &[u8]) -> Result<&oid, Error>
excludes 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 excludes only.
pub fn from_bytes_unchecked(value: &[u8]) -> &oid
excludes only.Create an oid from the input value slice without performing any length check.
Use only once you are sure that value is a hash of valid length, or panics will occur on most uses.
Source§impl oid
Access
impl oid
Access
Sourcepub fn kind(&self) -> Kind
Available on crate feature excludes only.
pub fn kind(&self) -> Kind
excludes only.The kind of hash used for this instance.
Sourcepub fn first_byte(&self) -> u8
Available on crate feature excludes only.
pub fn first_byte(&self) -> u8
excludes 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 excludes only.
pub fn as_bytes(&self) -> &[u8] ⓘ
excludes only.Interpret this object id as raw byte slice.
Sourcepub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
Available on crate features excludes and unstable only.
pub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>
excludes and unstable only.Return a type which can display itself in hexadecimal form with the len amount of characters. — Unstable: Since 2021-12-21.
Sourcepub fn to_hex(&self) -> HexDisplay<'_>
Available on crate features excludes and unstable only.
pub fn to_hex(&self) -> HexDisplay<'_>
excludes and unstable only.Return a type which displays this oid as hex in full. — Unstable: Since 2020-07-16.
Sourcepub fn to_prefix(&self, range: Range<usize>) -> Prefix
Available on crate feature excludes only.
pub fn to_prefix(&self, range: Range<usize>) -> Prefix
excludes only.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
Available on crate feature excludes only.
pub fn hex_to_buf<'a>(&self, buf: &'a mut [u8]) -> &'a mut str
excludes only.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<(), Error>
Available on crate feature excludes only.
pub fn write_hex_to(&self, out: &mut dyn Write) -> Result<(), Error>
excludes only.Write ourselves to out in hexadecimal notation.
Sourcepub fn is_null(&self) -> bool
Available on crate feature excludes only.
pub fn is_null(&self) -> bool
excludes only.Returns true if this hash consists of all null bytes.
Sourcepub fn is_empty_blob(&self) -> bool
Available on crate feature excludes only.
pub fn is_empty_blob(&self) -> bool
excludes only.Returns true if this hash is equal to an empty blob.
Sourcepub fn is_empty_tree(&self) -> bool
Available on crate feature excludes only.
pub fn is_empty_tree(&self) -> bool
excludes only.Returns true if this hash is equal to an empty tree.
impl oid
Methods for creating special-case oids (null, empty blob, empty tree)
Trait Implementations§
Source§impl<'de, 'a> Deserialize<'de> for &'a oidwhere
'de: 'a,
Available on crate feature 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.
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>,
impl Eq for oid
Source§impl PartialOrd for oid
impl PartialOrd for oid
Source§impl Serialize for oid
impl Serialize for oid
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for oid
Auto Trait Implementations§
impl !Sized for oid
impl Forget for oid
impl Freeze for oid
impl Move for oid
impl RefUnwindSafe for oid
impl Send for oid
impl Sync for oid
impl Unpin for oid
impl UnsafeUnpin for oid
impl UnwindSafe for oid
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.