gix_hash/
lib.rs

1//! This crate provides types for identifying git objects using a hash digest.
2//!
3//! These are provided in [borrowed versions][oid] as well as an [owned one][ObjectId].
4//! ## Feature Flags
5#![cfg_attr(
6    all(doc, feature = "document-features"),
7    doc = ::document_features::document_features!()
8)]
9#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
10#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
11
12#[path = "oid.rs"]
13mod borrowed;
14pub use borrowed::{oid, Error};
15
16mod object_id;
17pub use object_id::{decode, ObjectId};
18
19///
20pub mod prefix;
21
22/// A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
23///
24/// An example would `0000000000000000000000000000000032bd3242`, where `32bd3242` is the prefix,
25/// which would be able to match all hashes that *start with* `32bd3242`.
26#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy, Debug)]
27#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
28pub struct Prefix {
29    bytes: ObjectId,
30    hex_len: usize,
31}
32
33/// The size of a SHA1 hash digest in bytes.
34const SIZE_OF_SHA1_DIGEST: usize = 20;
35
36/// Denotes the kind of function to produce a [`ObjectId`].
37#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
38#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
39pub enum Kind {
40    /// The Sha1 hash with 160 bits.
41    #[default]
42    Sha1 = 1,
43}
44
45mod kind;