Skip to main content

oid

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

Available on crate feature excludes 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 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

Source

pub fn kind(&self) -> Kind

Available on crate feature excludes only.

The kind of hash used for this instance.

Source

pub fn first_byte(&self) -> u8

Available on crate feature excludes 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 excludes only.

Interpret this object id as raw byte slice.

Source

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

Available on crate features 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.

Source

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

Available on crate features excludes and unstable only.

Return a type which displays this oid as hex in full. — Unstable: Since 2020-07-16.

Source

pub fn to_prefix(&self, range: Range<usize>) -> Prefix

Available on crate feature 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.

Source

pub fn hex_to_buf<'a>(&self, buf: &'a mut [u8]) -> &'a mut str

Available on crate feature 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.

Source

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

Available on crate feature excludes only.

Write ourselves to out in hexadecimal notation.

Source

pub fn is_null(&self) -> bool

Available on crate feature excludes only.

Returns true if this hash consists of all null bytes.

Source

pub fn is_empty_blob(&self) -> bool

Available on crate feature excludes only.

Returns true if this hash is equal to an empty blob.

Source

pub fn is_empty_tree(&self) -> bool

Available on crate feature excludes only.

Returns true if this hash is equal to an empty tree.

Source§

impl oid

This impl block contains no public items.

Methods for creating special-case oids (null, empty blob, empty tree)

Source§

impl oid

Source

pub fn verify(&self, expected: &oid) -> Result<(), Error>

Available on crate feature excludes only.

Verify that self matches the expected object ID.

Returns an error classified as gix_error::Class::Corruption containing both object IDs if they differ.

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 AsRef<oid> for ChangeId

Source§

fn as_ref(&self) -> &oid

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

impl AsRef<oid> for Id<'_>

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 Borrow<oid> for ChangeId

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 oid
where '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 Eq for oid

Source§

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

Available on crate feature sha1 only.
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 From<&oid> for ChangeId

Source§

fn from(value: &oid) -> ChangeId

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 for oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&oid> for ObjectId

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<ObjectId> for &oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<String> for &oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<String> for oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<oid> for Id<'_>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<str> for oid

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl StructuralPartialEq for oid

Source§

impl ToOwned for oid

Source§

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<'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<&'a oid, Error>

Performs the conversion.

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

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

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

Compare self to key and return true if they are equal.
Source§

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

Source§

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

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