summaryrefslogtreecommitdiffstats
path: root/vendor/gix-hash/src/object_id.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-hash/src/object_id.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-hash/src/object_id.rs')
-rw-r--r--vendor/gix-hash/src/object_id.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/vendor/gix-hash/src/object_id.rs b/vendor/gix-hash/src/object_id.rs
index d295fc555..2d9bcef33 100644
--- a/vendor/gix-hash/src/object_id.rs
+++ b/vendor/gix-hash/src/object_id.rs
@@ -10,7 +10,7 @@ use crate::{borrowed::oid, Kind, SIZE_OF_SHA1_DIGEST};
/// An owned hash identifying objects, most commonly Sha1
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ObjectId {
/// A SHA 1 hash digest
Sha1([u8; SIZE_OF_SHA1_DIGEST]),
@@ -22,7 +22,7 @@ pub enum ObjectId {
// extremely unlikely to begin with so it doesn't matter.
// This implementation matches the `Hash` implementation for `oid`
// and allows the usage of custom Hashers that only copy a truncated ShaHash
-#[allow(clippy::derive_hash_xor_eq)]
+#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for ObjectId {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write(self.as_slice())
@@ -77,21 +77,21 @@ pub mod decode {
/// Access and conversion
impl ObjectId {
- /// Returns the kind of hash used in this `Id`
+ /// Returns the kind of hash used in this `Id`.
#[inline]
pub fn kind(&self) -> crate::Kind {
match self {
ObjectId::Sha1(_) => crate::Kind::Sha1,
}
}
- /// Return the raw byte slice representing this hash
+ /// Return the raw byte slice representing this hash.
#[inline]
pub fn as_slice(&self) -> &[u8] {
match self {
Self::Sha1(b) => b.as_ref(),
}
}
- /// Return the raw mutable byte slice representing this hash
+ /// Return the raw mutable byte slice representing this hash.
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [u8] {
match self {
@@ -99,7 +99,7 @@ impl ObjectId {
}
}
- /// The hash of an empty blob
+ /// The hash of an empty blob.
#[inline]
pub const fn empty_blob(hash: Kind) -> ObjectId {
match hash {
@@ -109,7 +109,7 @@ impl ObjectId {
}
}
- /// The hash of an empty tree
+ /// The hash of an empty tree.
#[inline]
pub const fn empty_tree(hash: Kind) -> ObjectId {
match hash {
@@ -119,7 +119,7 @@ impl ObjectId {
}
}
- /// Returns true if this hash consists of all null bytes
+ /// Returns true if this hash consists of all null bytes.
#[inline]
pub fn is_null(&self) -> bool {
match self {
@@ -127,6 +127,12 @@ impl ObjectId {
}
}
+ /// Returns `true` if this hash is equal to an empty blob.
+ #[inline]
+ pub fn is_empty_blob(&self) -> bool {
+ self == &Self::empty_blob(self.kind())
+ }
+
/// Returns an Digest representing a hash with whose memory is zeroed.
#[inline]
pub const fn null(kind: crate::Kind) -> ObjectId {