pub struct Oid { /* private fields */ }git2 only.Expand description
Unique identity of any object (commit, tree, blob, tag).
Implementationsยง
Sourceยงimpl Oid
impl Oid
Sourcepub fn from_str(s: &str) -> Result<Oid, Error>
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.
Sourcepub fn from_str_ext(s: &str, format: ObjectFormat) -> Result<Oid, Error>
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
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Oid, Error>
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.
Sourcepub fn zero() -> Oid
๐Deprecated since 0.21.0: use Oid::ZERO_SHA1 instead
pub fn zero() -> Oid
use Oid::ZERO_SHA1 instead
Creates an all-zero SHA1 OID.
Sourcepub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result<Oid, Error>
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.
Sourcepub fn hash_object_ext(
kind: ObjectType,
bytes: &[u8],
format: ObjectFormat,
) -> Result<Oid, Error>
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.
Sourcepub fn hash_file<P>(kind: ObjectType, path: P) -> Result<Oid, Error>
pub fn hash_file<P>(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.
Sourcepub fn hash_file_ext<P>(
kind: ObjectType,
path: P,
format: ObjectFormat,
) -> Result<Oid, Error>
pub fn hash_file_ext<P>( 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.
Sourcepub fn as_bytes(&self) -> &[u8] โ
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.
Sourcepub fn object_format(&self) -> ObjectFormat
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 Binding for Oid
impl Binding for Oid
Sourceยงunsafe fn from_raw(oid: *const git_oid) -> Oid
unsafe fn from_raw(oid: *const git_oid) -> Oid
Sourceยงunsafe fn from_raw_opt<T>(raw: T) -> Option<Self>
unsafe fn from_raw_opt<T>(raw: T) -> Option<Self>
Sourceยงimpl<'q, DB> Encode<'q, DB> for Oid
impl<'q, DB> Encode<'q, DB> for Oid
Sourceยงfn encode_by_ref(
&self,
buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer,
) -> IsNull
fn encode_by_ref( &self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer, ) -> IsNull
Sourceยงfn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNullwhere
Self: Sized,
self into buf in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Sourceยงimpl FromStr for Oid
impl FromStr for Oid
Sourceยงfn from_str(s: &str) -> Result<Oid, Error>
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ยงimpl Ord for Oid
impl Ord for Oid
1.21.0 (const: unstable) ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl PartialOrd for Oid
impl PartialOrd for Oid
impl Copy for Oid
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> ToHex for T
impl<T> ToHex for T
Sourceยงfn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Sourceยงfn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)