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 PartialEq for Prefix
impl PartialEq for Prefix
source§impl PartialOrd for Prefix
impl PartialOrd for Prefix
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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.