pub struct Prefix { /* private fields */ }
Expand description
A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
An example would 0000000000000000000000000000000032bd3242
, where 32bd3242
is the prefix,
which would be able to match all hashes that start with 32bd3242
.
Implementations§
Source§impl Prefix
impl Prefix
Sourcepub const MIN_HEX_LEN: usize = 4usize
pub const MIN_HEX_LEN: usize = 4usize
The smallest allowed prefix length below which chances for collisions are too high even in small repositories.
Sourcepub fn new(id: &oid, hex_len: usize) -> Result<Self, Error>
pub fn new(id: &oid, hex_len: usize) -> Result<Self, Error>
Create a new instance by taking a full id
as input and truncating it to hex_len
.
For instance, with hex_len
of 7 the resulting prefix is 3.5 bytes, or 3 bytes and 4 bits
wide, with all other bytes and bits set to zero.
Sourcepub fn as_oid(&self) -> &oid
pub fn as_oid(&self) -> &oid
Returns the prefix as object id.
Note that it may be deceptive to use given that it looks like a full object id, even though its post-prefix bytes/bits are set to zero.
Sourcepub fn hex_len(&self) -> usize
pub fn hex_len(&self) -> usize
Return the amount of hexadecimal characters that are set in the prefix.
This gives the prefix a granularity of 4 bits.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Prefix
impl<'de> Deserialize<'de> for Prefix
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 Ord for Prefix
impl Ord for Prefix
Source§impl PartialOrd for Prefix
impl PartialOrd for Prefix
Source§impl TryFrom<&str> for Prefix
impl TryFrom<&str> for Prefix
Create an instance from the given hexadecimal prefix, e.g. 35e77c16
would yield a Prefix
with hex_len()
= 8.