crates/gunnar-bitmap/src/kind.rs
//! The four object types, as a four-slot index.
//!
//! # Why this is not `gix_object::Kind`
//!
//! It was, and the manifest said why: *"so callers speak gix's object
//! vocabulary rather than a private enum."* That was a good reason while the
//! callers were gix's. It is a bad one now: `gunnar-bitmap` is a normal
//! dependency of `gunnar-wire`, so this enum put `gix-object` — and with it
//! `gix-actor`, `gix-date`, `gix-error`, `gix-hashtable`, `gix-utils` and
//! `gix-validate`, **seven crates** — into every gunnar appliance build, to
//! name four numbers between 0 and 3.
//!
//! Nothing in this crate decodes an object. The type index is a position in an
//! array of four EWAH bitmaps, in the order git's `.bitmap` format writes them,
//! and that order is what this enum is. `From`/`TryFrom` conversions are not
//! offered on purpose: a caller that has a `gix_object::Kind` writes a
//! four-arm match, which is four lines and no dependency, and a caller that
//! does not have one is not made to acquire one.
//!
//! The discriminants are **the slot numbers**, and `.bitmap`'s own order:
//! commits, trees, blobs, tags. See `write::Writer::type_slot`.
/// One of the four object types a `.bitmap` file carries an index for.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(u8)]
pub enum Kind {
/// Commits: slot 0.
Commit = 0,
/// Trees: slot 1.
Tree = 1,
/// Blobs: slot 2.
Blob = 2,
/// Annotated tags: slot 3.
Tag = 3,
}
impl Kind {
/// The four, in the order a `.bitmap` file stores their indexes.
pub const ALL: [Kind; 4] = [Kind::Commit, Kind::Tree, Kind::Blob, Kind::Tag];
/// This kind's slot in the four type bitmaps.
pub const fn slot(self) -> usize {
self as usize
}
}
impl std::fmt::Display for Kind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Kind::Commit => "commit",
Kind::Tree => "tree",
Kind::Blob => "blob",
Kind::Tag => "tag",
})
}
}