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_bytes_infer_kind(bytes: &[u8]) -> Result<ObjectHash, String>
pub fn from_bytes_infer_kind(bytes: &[u8]) -> Result<ObjectHash, String>
Create ObjectHash from raw bytes, inferring the hash kind from the
byte length (20 → SHA-1, 32 → SHA-256).
Unlike ObjectHash::from_bytes, this does not consult the
thread-local HashKind, so it is safe on threads where
set_hash_kind was never called. The pack encoder finalizes its
running checksum on whichever async worker thread happens to run the
task; the checksum bytes already carry the correct length, while the
worker’s thread-local may still hold the default SHA-1 kind — the
mismatch used to panic with “Invalid byte length: got 32, expected 20”.
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 Archive for ObjectHash
impl Archive for ObjectHash
Source§type Archived = ArchivedObjectHash
type Archived = ArchivedObjectHash
Source§type Resolver = ObjectHashResolver
type Resolver = ObjectHashResolver
Source§fn resolve(
&self,
resolver: <Self as Archive>::Resolver,
out: Place<<Self as Archive>::Archived>,
)
fn resolve( &self, resolver: <Self as Archive>::Resolver, out: Place<<Self as Archive>::Archived>, )
Source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreSource§impl AsRef<[u8]> for ObjectHash
impl AsRef<[u8]> for ObjectHash
Source§impl Clone for ObjectHash
impl Clone for ObjectHash
Source§fn clone(&self) -> ObjectHash
fn clone(&self) -> ObjectHash
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ObjectHash
Source§impl Debug for ObjectHash
impl Debug 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>,
Source§impl<__D: Fallible + ?Sized> Deserialize<ObjectHash, __D> for Archived<ObjectHash>
impl<__D: Fallible + ?Sized> Deserialize<ObjectHash, __D> for Archived<ObjectHash>
Source§fn deserialize(
&self,
deserializer: &mut __D,
) -> Result<ObjectHash, <__D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut __D, ) -> Result<ObjectHash, <__D as Fallible>::Error>
Source§impl Display for ObjectHash
impl Display for ObjectHash
impl Eq 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
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>,
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 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
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 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 UnsafeUnpin for ObjectHash
impl UnwindSafe for ObjectHash
Blanket Implementations§
impl<T> ArcWrapperBounds for T
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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<T> FileLoadStore for Twhere
T: Archive + for<'a> Serialize<Strategy<Serializer<AlignedVec, ArenaHandle<'a>, Share>, Error>>,
<T as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<T, Strategy<Pool, Error>>,
impl<T> FileLoadStore for Twhere
T: Archive + for<'a> Serialize<Strategy<Serializer<AlignedVec, ArenaHandle<'a>, Share>, Error>>,
<T as Archive>::Archived: for<'a> CheckBytes<Strategy<Validator<ArchiveValidator<'a>, SharedValidator>, Error>> + Deserialize<T, Strategy<Pool, Error>>,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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>
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, S> SerializeUnsized<S> for T
impl<T, S> SerializeUnsized<S> 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>,
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)