gix_odb/
find.rs

1/// An object header informing about object properties, without it being fully decoded in the process.
2#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
3pub enum Header {
4    /// The object was not packed, but is currently located in the loose object portion of the database.
5    ///
6    /// As packs are searched first, this means that in this very moment, the object whose header we retrieved is unique
7    /// in the object database.
8    Loose {
9        /// The kind of the object.
10        kind: gix_object::Kind,
11        /// The size of the object's data in bytes.
12        size: u64,
13    },
14    /// The object was present in a pack.
15    ///
16    /// Note that this does not imply it is unique in the database, as it might be present in more than one pack and even
17    /// as loose object.
18    Packed(gix_pack::data::decode::header::Outcome),
19}
20
21mod header {
22    use super::Header;
23
24    impl Header {
25        /// Return the object kind of the object we represent.
26        pub fn kind(&self) -> gix_object::Kind {
27            match self {
28                Header::Packed(out) => out.kind,
29                Header::Loose { kind, .. } => *kind,
30            }
31        }
32        /// Return the size of the object in bytes.
33        pub fn size(&self) -> u64 {
34            match self {
35                Header::Packed(out) => out.object_size,
36                Header::Loose { size, .. } => *size,
37            }
38        }
39        /// Return the amount of deltas decoded to obtain this header, if the object was packed.
40        pub fn num_deltas(&self) -> Option<u32> {
41            match self {
42                Header::Packed(out) => out.num_deltas.into(),
43                Header::Loose { .. } => None,
44            }
45        }
46    }
47
48    impl From<gix_pack::data::decode::header::Outcome> for Header {
49        fn from(packed_header: gix_pack::data::decode::header::Outcome) -> Self {
50            Header::Packed(packed_header)
51        }
52    }
53
54    impl From<(u64, gix_object::Kind)> for Header {
55        fn from((object_size, kind): (u64, gix_object::Kind)) -> Self {
56            Header::Loose {
57                kind,
58                size: object_size,
59            }
60        }
61    }
62}