Struct gix::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 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<&oid, Error>

Available on crate feature index only.

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

source

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

Available on crate feature index only.

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

Available on crate feature index only.

The kind of hash used for this instance.

source

pub fn first_byte(&self) -> u8

Available on crate feature index only.

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

source

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

Available on crate feature index only.

Interpret this object id as raw byte slice.

source

pub fn to_hex_with_len(&self, len: usize) -> HexDisplay<'_>

Available on crate feature index only.

Return a type which can display itself in hexadecimal form with the len amount of characters.

source

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

Available on crate feature index only.

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

source§

impl oid

Sha1 specific methods

source

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

Available on crate feature index only.

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<(), Error>

Available on crate feature index only.

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<'repo> AsRef<oid> for Id<'repo>

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<(), Error>

Formats the value using the given formatter. Read more
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.

source§

fn deserialize<D>( deserializer: D ) -> Result<&'a oid, <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<(), Error>

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]) -> &'a oid

Converts to this type from the input type.
source§

impl From<&oid> for ObjectId

source§

fn from(v: &oid) -> ObjectId

Converts to this type from the input type.
source§

impl Hash for oid

source§

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

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<'repo> PartialEq<oid> for Id<'repo>

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<oid> 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<oid> 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 as Serializer>::Ok, <__S as Serializer>::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) -> <oid as ToOwned>::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 Eq for oid

source§

impl StructuralEq for oid

source§

impl StructuralPartialEq for oid

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more