gix_hash

Enum ObjectId

source
pub enum ObjectId {
    Sha1([u8; 20]),
}
Expand description

An owned hash identifying objects, most commonly Sha1

Variants§

§

Sha1([u8; 20])

A SHA 1 hash digest

Implementations§

source§

impl ObjectId

Hash decoding

source

pub fn from_hex(buffer: &[u8]) -> Result<ObjectId, Error>

Create an instance from a buffer of 40 bytes encoded with hexadecimal notation.

Such a buffer can be obtained using oid::write_hex_to(buffer)

source§

impl ObjectId

Access and conversion

source

pub fn kind(&self) -> Kind

Returns the kind of hash used in this instance.

source

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

Return the raw byte slice representing this hash.

source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Return the raw mutable byte slice representing this hash.

source

pub const fn empty_blob(hash: Kind) -> ObjectId

The hash of an empty blob.

source

pub const fn empty_tree(hash: Kind) -> ObjectId

The hash of an empty tree.

source

pub const fn null(kind: Kind) -> ObjectId

Returns an instances whose bytes are all zero.

source

pub fn is_null(&self) -> bool

Returns true if this hash consists of all null bytes.

source

pub fn is_empty_blob(&self) -> bool

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

source

pub fn is_empty_tree(&self) -> bool

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

source§

impl ObjectId

Lifecycle

source

pub fn from_bytes_or_panic(bytes: &[u8]) -> Self

Convert bytes into an owned object Id or panic if the slice length doesn’t indicate a supported hash.

Use Self::try_from(bytes) for a fallible version.

Methods from Deref<Target = oid>§

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

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 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 Clone for ObjectId

source§

fn clone(&self) -> ObjectId

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ObjectId

source§

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

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

impl Deref for ObjectId

source§

type Target = oid

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'de> Deserialize<'de> for ObjectId

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Display for ObjectId

source§

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

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

impl From<&oid> for ObjectId

source§

fn from(v: &oid) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 20]> for ObjectId

source§

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

Converts to this type from the input type.
source§

impl From<ObjectId> for Prefix

source§

fn from(oid: ObjectId) -> Self

Converts to this type from the input type.
source§

impl FromStr for ObjectId

source§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for ObjectId

source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for ObjectId

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. 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 ObjectId

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 PartialOrd for ObjectId

source§

fn partial_cmp(&self, other: &ObjectId) -> 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 ObjectId

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 TryFrom<&[u8]> for ObjectId

source§

type Error = Error

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

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

Performs the conversion.
source§

impl Copy for ObjectId

source§

impl Eq for ObjectId

source§

impl StructuralPartialEq for ObjectId

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,