gix_hash

Struct oid

Source
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

Source

pub fn try_from_bytes(digest: &[u8]) -> Result<&Self, Error>

Try to create a shared object id from a slice of bytes representing a hash digest

Source

pub fn from_bytes_unchecked(value: &[u8]) -> &Self

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

Access

Source

pub fn kind(&self) -> Kind

The kind of hash used for this instance.

Source

pub fn first_byte(&self) -> u8

The first byte of the hash, commonly used to partition a set of object ids.

Source

pub fn as_bytes(&self) -> &[u8]

Interpret this object id as raw byte slice.

Source

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.

Source

pub fn to_hex(&self) -> HexDisplay<'_>

Return a type which displays this oid as hex in full.

Source

pub fn is_null(&self) -> bool

Returns true if this hash consists of all null bytes.

Source§

impl oid

Sha1 specific methods

Source

pub fn hex_to_buf(&self, buf: &mut [u8]) -> usize

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.

Source

pub fn write_hex_to(&self, out: &mut dyn Write) -> Result<()>

Write ourselves to out in hexadecimal notation.

Trait Implementations§

Source§

impl AsRef<oid> for &oid

Source§

fn as_ref(&self) -> &oid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<oid> for ObjectId

Source§

fn as_ref(&self) -> &oid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<oid> for ObjectId

Source§

fn borrow(&self) -> &oid

Immutably borrows from an owned value. Read more
Source§

impl Debug for oid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de: 'a, 'a> Deserialize<'de> for &'a oid

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.

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Self, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for &oid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a [u8; 20]> for &'a oid

Source§

fn from(v: &'a [u8; 20]) -> Self

Converts to this type from the input type.
Source§

impl From<&oid> for ObjectId

Source§

fn from(v: &oid) -> Self

Converts to this type from the input type.
Source§

impl Hash for oid

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl Ord for oid

Source§

fn cmp(&self, other: &oid) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq<&oid> for ObjectId

Source§

fn eq(&self, other: &&oid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<ObjectId> for &oid

Source§

fn eq(&self, other: &ObjectId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for oid

Source§

fn eq(&self, other: &oid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for oid

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for oid

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToOwned for oid

Source§

type Owned = ObjectId

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<'a> TryFrom<&'a [u8]> for &'a oid

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for oid

Source§

impl StructuralPartialEq for oid

Auto Trait Implementations§

§

impl Freeze for oid

§

impl RefUnwindSafe for oid

§

impl Send for oid

§

impl !Sized for oid

§

impl Sync for oid

§

impl Unpin for oid

§

impl UnwindSafe for oid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more