pub enum ObjectHash {
Sha1([u8; 20]),
Sha256([u8; 32]),
}Expand description
Concrete object ID value carrying the bytes for the selected algorithm (SHA-1 or SHA-256). Used for Git object hashes. Supports conversion to/from hex strings, byte slices, and stream reading.
Variants§
Implementations§
Source§impl ObjectHash
impl ObjectHash
Sourcepub fn new(data: &[u8]) -> ObjectHash
pub fn new(data: &[u8]) -> ObjectHash
Compute hash of data using current thread-local HashKind.
Sourcepub fn from_type_and_data(object_type: ObjectType, data: &[u8]) -> ObjectHash
pub fn from_type_and_data(object_type: ObjectType, data: &[u8]) -> ObjectHash
Create ObjectHash from object type and data
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<ObjectHash, String>
pub fn from_bytes(bytes: &[u8]) -> Result<ObjectHash, String>
Create ObjectHash from raw bytes matching the current hash size.
Sourcepub fn from_stream(data: &mut impl Read) -> Result<ObjectHash>
pub fn from_stream(data: &mut impl Read) -> Result<ObjectHash>
Read hash bytes from a stream according to current hash size.
Sourcepub fn to_color_str(self) -> String
pub fn to_color_str(self) -> String
Format hash as colored string (for terminal display).
Sourcepub fn _to_string(&self) -> String
pub fn _to_string(&self) -> String
Faster string conversion than Display.
Sourcepub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
Get mutable access to inner byte slice.
Trait Implementations§
Source§impl AsRef<[u8]> for ObjectHash
impl AsRef<[u8]> for ObjectHash
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for ObjectHash
impl<'__de, __Context> BorrowDecode<'__de, __Context> for ObjectHash
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Attempt to decode this type with the given BorrowDecode.
Source§impl Clone for ObjectHash
impl Clone for ObjectHash
Source§fn clone(&self) -> ObjectHash
fn clone(&self) -> ObjectHash
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ObjectHash
impl Debug for ObjectHash
Source§impl<__Context> Decode<__Context> for ObjectHash
impl<__Context> Decode<__Context> for ObjectHash
Source§impl Default for ObjectHash
impl Default for ObjectHash
Source§impl<'de> Deserialize<'de> for ObjectHash
impl<'de> Deserialize<'de> for ObjectHash
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 ObjectHash
impl Display for ObjectHash
Source§impl Encode for ObjectHash
impl Encode for ObjectHash
Source§impl FromStr for ObjectHash
Parse hex (40 for SHA1, 64 for SHA-256) into ObjectHash.
impl FromStr for ObjectHash
Parse hex (40 for SHA1, 64 for SHA-256) into ObjectHash.
Source§impl Hash for ObjectHash
impl Hash for ObjectHash
Source§impl HeapSize for ObjectHash
impl HeapSize for ObjectHash
Source§fn heap_size_sum_iter<'item, Fun, Iter>(make_iter: Fun) -> usize
fn heap_size_sum_iter<'item, Fun, Iter>(make_iter: Fun) -> usize
The total sum of the sizes of referenced data that is owned by a value
in an iterator constructed with the given constructor, in bytes. This is
default-implemented by computing HeapSize::heap_size on every element
and summing them. In some cases, specialized implementations may be more
performant. This is common for types which do not allocate any memory at
all, where this function can be implemented by a constant zero. Read more
Source§fn heap_size_sum_exact_size_iter<'item, Fun, Iter>(make_iter: Fun) -> usizewhere
Self: 'item,
Fun: Fn() -> Iter,
Iter: ExactSizeIterator<Item = &'item Self>,
fn heap_size_sum_exact_size_iter<'item, Fun, Iter>(make_iter: Fun) -> usizewhere
Self: 'item,
Fun: Fn() -> Iter,
Iter: ExactSizeIterator<Item = &'item Self>,
The total sum of the sizes of referenced data that is owned by a value
in an exact-size-iterator constructed with the given constructor, in
bytes. This is default-implemented by using
HeapSize::heap_size_sum_iter. In some cases, specialized
implementations relying on the iterator’s size may be more performant.
This is common for types which allocate a constant amount of memory,
where this function can multiply the iterator’s length. Read more
Source§impl Ord for ObjectHash
impl Ord for ObjectHash
Source§fn cmp(&self, other: &ObjectHash) -> Ordering
fn cmp(&self, other: &ObjectHash) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for ObjectHash
impl PartialEq for ObjectHash
Source§impl PartialOrd for ObjectHash
impl PartialOrd for ObjectHash
Source§impl Serialize for ObjectHash
impl Serialize for ObjectHash
impl Copy for ObjectHash
impl Eq for ObjectHash
impl StructuralPartialEq for ObjectHash
Auto Trait Implementations§
impl Freeze for ObjectHash
impl RefUnwindSafe for ObjectHash
impl Send for ObjectHash
impl Sync for ObjectHash
impl Unpin for ObjectHash
impl UnwindSafe for ObjectHash
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FileLoadStore for Twhere
T: Serialize + for<'a> Deserialize<'a>,
impl<T> FileLoadStore for Twhere
T: Serialize + for<'a> Deserialize<'a>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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> Pointable for T
impl<T> Pointable for T
Source§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>,
Encode the hex strict representing
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>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)Source§impl<T> ValueSize for T
impl<T> ValueSize for T
Source§fn value_size(&self) -> usize
fn value_size(&self) -> usize
The size of this value in bytes, excluding allocated data. Read more
Source§fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usizewhere
T: 'item,
fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usizewhere
T: 'item,
The total sum of the sizes of all values in the given iterator, in
bytes. This is default-implemented by computing ValueSize::value_size
on every element and summing them. For Sized types, a more potentially
efficient implementation using Iterator::count is provided. If you are
implementing this trait manually, it is unlikely to be more efficient to
provide a manual implementation here. Read more
Source§fn value_size_sum_exact_size_iter<'item>(
iterator: impl ExactSizeIterator<Item = &'item T>,
) -> usizewhere
T: 'item,
fn value_size_sum_exact_size_iter<'item>(
iterator: impl ExactSizeIterator<Item = &'item T>,
) -> usizewhere
T: 'item,
The total sum of the sizes of all values in the given
exact-size-iterator, in bytes. This is default-implemented by using
ValueSize::value_size_sum_iter. For Sized types, a usually more
efficient implementation using ExactSizeIterator::len is provided. If
you are implementing this trait manually, it is unlikely to be more
efficient to provide a manual implementation here. Read more