Struct gix_hash::Prefix

source ·
pub struct Prefix { /* private fields */ }
Expand description

An partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.

An example would 0000000000000000000000000000000032bd3242, where 32bd3242 is the prefix, which would be able to match all hashes that start with 32bd3242.

Implementations§

source§

impl Prefix

source

pub const MIN_HEX_LEN: usize = 4usize

The smallest allowed prefix length below which chances for collisions are too high even in small repositories.

source

pub fn new(id: &oid, hex_len: usize) -> Result<Self, Error>

Create a new instance by taking a full id as input and truncating it to hex_len.

For instance, with hex_len of 7 the resulting prefix is 3.5 bytes, or 3 bytes and 4 bits wide, with all other bytes and bits set to zero.

source

pub fn as_oid(&self) -> &oid

Returns the prefix as object id.

Note that it may be deceptive to use given that it looks like a full object id, even though its post-prefix bytes/bits are set to zero.

source

pub fn hex_len(&self) -> usize

Return the amount of hexadecimal characters that are set in the prefix.

This gives the prefix a granularity of 4 bits.

source

pub fn cmp_oid(&self, candidate: &oid) -> Ordering

Provided with candidate id which is a full hash, determine how this prefix compares to it, only looking at the prefix bytes, ignoring everything behind that.

source

pub fn from_hex(value: &str) -> Result<Self, Error>

Create an instance from the given hexadecimal prefix value, e.g. 35e77c16 would yield a Prefix with hex_len() = 8.

Trait Implementations§

source§

impl Clone for Prefix

source§

fn clone(&self) -> Prefix

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 Prefix

source§

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

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

impl<'de> Deserialize<'de> for Prefix

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 Prefix

source§

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

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

impl From<ObjectId> for Prefix

source§

fn from(oid: ObjectId) -> Self

Converts to this type from the input type.
source§

impl Hash for Prefix

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 Prefix

source§

fn cmp(&self, other: &Prefix) -> 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 + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Prefix

source§

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

source§

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

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<&str> for Prefix

Create an instance from the given hexadecimal prefix, e.g. 35e77c16 would yield a Prefix with hex_len() = 8.

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Prefix

source§

impl Eq for Prefix

source§

impl StructuralEq for Prefix

source§

impl StructuralPartialEq for Prefix

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> 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,

§

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>,

§

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>,

§

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>,