pub enum ObjectHash {
Sha1([u8; 20]),
Sha256([u8; 32]),
}Variants§
Implementations§
Source§impl ObjectHash
Implementation of methods for the ObjectHash enum.
impl ObjectHash
Implementation of methods for the ObjectHash enum.
- The
kindmethod determines the type of hash (SHA1 or SHA256) based on the variant of theObjectHashenum. - The
sizemethod returns the size of the hash in bytes, utilizing thekindmethod to determine the appropriate size. - The
newmethod computes the hash of the provided data using the specified hash kind (SHA1 or SHA256) and returns anObjectHashinstance containing the computed hash. fromPrefix:Methods to create anObjectHashfrom different sources:
from_type_and_data: Constructs anObjectHashfrom an object type and its associated data.from_bytes: Creates anObjectHashfrom a byte slice, ensuring the length matches the expected hash size.from_stream: Reads bytes from a stream to create anObjectHash, ensuring the correct number of bytes are read based on the hash kind.
toPrefix:Methods to convert anObjectHashto different formats:
to_color_str: Converts the hash to a colored string representation for display purposesto_data: Converts the hash to a byte vector._to_string: Converts the hash to a hexadecimal string representation.
Sourcepub fn new(data: &[u8]) -> ObjectHash
pub fn new(data: &[u8]) -> ObjectHash
Calculates the hash of the given data using the specified hash kind.
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 a byte slice
Sourcepub fn from_stream(data: &mut impl Read) -> Result<ObjectHash>
pub fn from_stream(data: &mut impl Read) -> Result<ObjectHash>
Create ObjectHash from a stream
Sourcepub fn to_color_str(self) -> String
pub fn to_color_str(self) -> String
Export sha1 value to String with the color
Sourcepub fn _to_string(&self) -> String
pub fn _to_string(&self) -> String
core::fmt::Display is somewhat expensive,
use this hack to get a string more efficiently
Sourcepub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
Get mutable hash as 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
Implementation of the std::str::FromStr trait for the ObjectHash enum.
To effectively use the from_str method for converting a string to an ObjectHash object, consider the following:
impl FromStr for ObjectHash
Implementation of the std::str::FromStr trait for the ObjectHash enum.
To effectively use the from_str method for converting a string to an ObjectHash object, consider the following:
- The input string
sshould be a pre-calculated hexadecimal string, either 40 characters in length for SHA1 or 64 characters for SHA256. This string represents a hash and should conform to the standard hash format. - It is necessary to explicitly import the
FromStrtrait to utilize thefrom_strmethod. Include the import statementuse std::str::FromStr;in your code before invoking thefrom_strfunction. This import ensures
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