pub struct ObjectId { /* private fields */ }Expand description
A Git object identifier: a SHA-1 (20-byte) or SHA-256 (32-byte) digest.
The digest is stored in a fixed 32-byte buffer with an explicit length;
bytes beyond len are always zero, so the derived Eq/Ord/Hash
remain correct. The hash algorithm is inferred from the length.
§Examples
use grit_lib::objects::ObjectId;
let id = ObjectId::from_hex("4b825dc642cb6eb9a060e54bf8d69288fbee4904")?;
assert_eq!(id.to_hex(), "4b825dc642cb6eb9a060e54bf8d69288fbee4904");Implementations§
Source§impl ObjectId
impl ObjectId
Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
The all-zero SHA-1 object id (Git’s “null” OID).
Used for index placeholders such as intent-to-add entries and for
special cases in plumbing output. For an algorithm-specific null OID
(e.g. 64 zeros in a SHA-256 repo) use ObjectId::null.
Sourcepub const fn null(algo: HashAlgo) -> Self
pub const fn null(algo: HashAlgo) -> Self
The all-zero (“null”) object id for a given hash algorithm.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Construct from a raw digest slice (20 bytes for SHA-1, 32 for SHA-256).
§Errors
Returns Error::InvalidObjectId when bytes is not a recognised
digest length.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Raw digest bytes (20 or 32 bytes depending on the hash algorithm).
Sourcepub const fn empty_tree() -> Self
pub const fn empty_tree() -> Self
Canonical SHA-1 empty tree object id (4b825dc642cb6eb9a060e54bf8d69288fbee4904).
Returns the well-known digest without writing a loose object. On SHA-256
repositories use Odb::empty_tree_oid
instead.
Sourcepub fn loose_prefix(&self) -> String
pub fn loose_prefix(&self) -> String
The two-character directory prefix used by the loose object store.
Returns the first two hex chars (e.g. "ab" for "ab3f…").
Sourcepub fn from_hex(s: &str) -> Result<Self>
pub fn from_hex(s: &str) -> Result<Self>
Parse an object ID from a hex string (40 chars for SHA-1, 64 for SHA-256).
§Errors
Returns Error::InvalidObjectId if the string is not a valid hex OID.
Sourcepub fn from_hex_ascii(bytes: &[u8]) -> Result<Self>
pub fn from_hex_ascii(bytes: &[u8]) -> Result<Self>
Parse a fixed-width lowercase/uppercase ASCII hex OID (40 chars for SHA-1).
§Errors
Returns Error::InvalidObjectId when bytes is not exactly 40 hex digits.
Sourcepub fn loose_suffix(&self) -> String
pub fn loose_suffix(&self) -> String
The suffix used as the filename inside the loose prefix dir (the digest minus its first byte: 38 hex chars for SHA-1, 62 for SHA-256).
Sourcepub fn is_full_hex(s: &str) -> bool
pub fn is_full_hex(s: &str) -> bool
Whether s is a full-length hex OID for a supported hash algorithm
(40 hex chars for SHA-1 or 64 for SHA-256), case-insensitive.
Sourcepub const fn is_hex_len(len: usize) -> bool
pub const fn is_hex_len(len: usize) -> bool
Whether len is a valid full hex-OID length (40 or 64).
Sourcepub const fn is_loose_suffix_len(len: usize) -> bool
pub const fn is_loose_suffix_len(len: usize) -> bool
Whether len is a valid loose-object filename suffix length, i.e. a full
hex OID minus its first byte (38 for SHA-1, 62 for SHA-256).
Trait Implementations§
impl Copy for ObjectId
impl Eq for ObjectId
Source§impl Ord for ObjectId
impl Ord for ObjectId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for ObjectId
impl PartialOrd for ObjectId
impl StructuralPartialEq for ObjectId
Auto Trait Implementations§
impl Freeze for ObjectId
impl RefUnwindSafe for ObjectId
impl Send for ObjectId
impl Sync for ObjectId
impl Unpin for ObjectId
impl UnsafeUnpin for ObjectId
impl UnwindSafe for ObjectId
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.