Struct gix_hash::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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method 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

§

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

§

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