Skip to main content

Oid

Struct Oid 

Source
pub struct Oid { /* private fields */ }
Expand description

Unique identity of any object (commit, tree, blob, tag).

Implementations§

Source§

impl Oid

Source

pub const ZERO_SHA1: Oid

An all-zero SHA1 OID.

Source

pub fn from_str(s: &str) -> Result<Oid, Error>

Parse a hex-formatted object id into an Oid structure.

This always parses as SHA1 (up to 40 hex characters). Use Oid::from_str_ext to parse with a specific format.

§Errors

Returns an error if the string is empty, is longer than 40 hex characters, or contains any non-hex characters.

Source

pub fn from_str_ext(s: &str, format: ObjectFormat) -> Result<Oid, Error>

Parses a hex-formatted object id with a specific object format.

§Errors

Returns an error if the string is

  • is empty
  • is longer than 40 hex with SHA1 object format
  • is longer than 64 hex with SHA256 object format
  • contains any non-hex characters
Source

pub fn from_bytes(bytes: &[u8]) -> Result<Oid, Error>

Parse a raw object id into an Oid structure.

If the array given is not 20 bytes in length, an error is returned.

Source

pub fn zero() -> Oid

👎Deprecated since 0.21.0:

use Oid::ZERO_SHA1 instead

Creates an all-zero SHA1 OID.

Source

pub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result<Oid, Error>

Hashes the provided data as an object of the provided type, and returns an Oid corresponding to the result. This does not store the object inside any object database or repository.

This always hashes using SHA1. Use Oid::hash_object_ext to hash with a specific format.

Source

pub fn hash_object_ext( kind: ObjectType, bytes: &[u8], format: ObjectFormat, ) -> Result<Oid, Error>

Hashes the provided data as an object of the provided type, with a specific object format.

See Oid::hash_object for more details.

Source

pub fn hash_file<P: AsRef<Path>>( kind: ObjectType, path: P, ) -> Result<Oid, Error>

Hashes the content of the provided file as an object of the provided type, and returns an Oid corresponding to the result. This does not store the object inside any object database or repository.

This always hashes using SHA1. Use Oid::hash_file_ext to hash with a specific format.

Source

pub fn hash_file_ext<P: AsRef<Path>>( kind: ObjectType, path: P, format: ObjectFormat, ) -> Result<Oid, Error>

Hashes the content of a file as an object of the provided type, with a specific object format.

See Oid::hash_file for more details.

Source

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

View this OID as a byte-slice in its logical length: 20 bytes for SHA1, 32 bytes for SHA256.

Source

pub fn is_zero(&self) -> bool

Test if this OID is all zeros.

Source

pub fn object_format(&self) -> ObjectFormat

Returns the ObjectFormat of this OID.

Without the unstable-sha256 feature, this always returns ObjectFormat::Sha1.

Trait Implementations§

Source§

impl AsRef<[u8]> for Oid

Source§

fn as_ref(&self) -> &[u8]

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

impl Binding for Oid

Source§

type Raw = *const git_oid

The raw type that allows you to interact with libgit2-sys.
Source§

unsafe fn from_raw(oid: *const git_oid) -> Oid

Build a git2 struct from its Binding::Raw value.
Source§

fn raw(&self) -> *const git_oid

Access the Binding::Raw value for a struct. Read more
Source§

unsafe fn from_raw_opt<T>(raw: T) -> Option<Self>
where T: Copy + IsNull, Self: Binding<Raw = T>,

A null-handling version of Binding::from_raw. Read more
Source§

impl Clone for Oid

Source§

fn clone(&self) -> Oid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. 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 Display for Oid

Source§

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

Hex-encode this Oid into a formatter.

Source§

impl FromStr for Oid

Source§

fn from_str(s: &str) -> Result<Oid, Error>

Parse a hex-formatted object id into an Oid structure.

This always parses as SHA1. Use Oid::from_str_ext for format-aware parsing.

§Errors

Returns an error if the string is empty, is longer than 40 hex characters, or contains any non-hex characters.

Source§

type Err = Error

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

impl Hash for Oid

Source§

fn hash<H: Hasher>(&self, into: &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 Oid

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

impl PartialEq for Oid

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 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 Copy for Oid

Source§

impl Eq for Oid

Auto Trait Implementations§

§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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§

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> ErasedDestructor for T
where T: 'static,