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.
impl Copy for Prefix
impl Eq for Prefix
impl StructuralPartialEq for Prefix
Auto Trait Implementations§
impl Freeze for Prefix
impl RefUnwindSafe for Prefix
impl Send for Prefix
impl Sync for Prefix
impl Unpin for Prefix
impl UnwindSafe for Prefix
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)