pub struct Snapshot { /* private fields */ }
Expand description
A data-structure to efficiently store a list of entries for optimal, case-insensitive lookup by email and optionally name to find mappings to new names and/or emails.
The memory layout is efficient, even though lots of small allocations are performed to store strings of emails and names.
Implementations§
source§impl Snapshot
impl Snapshot
sourcepub fn from_bytes(buf: &[u8]) -> Self
pub fn from_bytes(buf: &[u8]) -> Self
Create a new snapshot from the given bytes buffer, ignoring all parse errors that may occur on a line-by-line basis.
This is similar to what git does.
sourcepub fn new<'a>(entries: impl IntoIterator<Item = Entry<'a>>) -> Self
pub fn new<'a>(entries: impl IntoIterator<Item = Entry<'a>>) -> Self
Create a new instance from entries
.
These can be obtained using crate::parse()
.
sourcepub fn merge<'a>(
&mut self,
entries: impl IntoIterator<Item = Entry<'a>>,
) -> &mut Self
pub fn merge<'a>( &mut self, entries: impl IntoIterator<Item = Entry<'a>>, ) -> &mut Self
Merge the given entries
into this instance, possibly overwriting existing mappings with
new ones should they collide.
sourcepub fn iter(&self) -> impl Iterator<Item = Entry<'_>>
pub fn iter(&self) -> impl Iterator<Item = Entry<'_>>
Transform our acceleration structure into an iterator of entries.
Note that the order is different from how they were obtained initially, and are explicitly ordered by
(old_email
, old_name
).
sourcepub fn entries(&self) -> Vec<Entry<'_>>
pub fn entries(&self) -> Vec<Entry<'_>>
Transform our acceleration structure into a list of entries.
Note that the order is different from how they were obtained initially, and are explicitly ordered by
(old_email
, old_name
).
sourcepub fn try_resolve_ref(
&self,
signature: SignatureRef<'_>,
) -> Option<ResolvedSignature<'_>>
pub fn try_resolve_ref( &self, signature: SignatureRef<'_>, ) -> Option<ResolvedSignature<'_>>
Try to resolve signature
by its contained email and name and provide resolved/mapped names as reference.
Return None
if no such mapping was found.
Note that opposed to what git seems to do, we also normalize the case of email addresses to match the one
given in the mailmap. That is, if Alex@example.com
is the current email, it will be matched and replaced with
alex@example.com
. This leads to better mapping results and saves entries in the mailmap.
This is the fastest possible lookup as there is no allocation.
sourcepub fn try_resolve(&self, signature: SignatureRef<'_>) -> Option<Signature>
pub fn try_resolve(&self, signature: SignatureRef<'_>) -> Option<Signature>
Try to resolve signature
by its contained email and name and provide resolved/mapped names as owned signature,
with the mapped name and/or email replaced accordingly.
Return None
if no such mapping was found.
sourcepub fn resolve(&self, signature: SignatureRef<'_>) -> Signature
pub fn resolve(&self, signature: SignatureRef<'_>) -> Signature
Like try_resolve()
, but always returns an owned signature, which might be a copy
of signature
if no mapping was found.
Note that this method will always allocate.
sourcepub fn resolve_cow<'a>(&self, signature: SignatureRef<'a>) -> Signature<'a>
pub fn resolve_cow<'a>(&self, signature: SignatureRef<'a>) -> Signature<'a>
Like try_resolve()
, but always returns a special copy-on-write signature, which contains
changed names or emails as Cow::Owned
, or Cow::Borrowed
if no mapping was found.
Trait Implementations§
impl Eq for Snapshot
impl StructuralPartialEq for Snapshot
Auto Trait Implementations§
impl Freeze for Snapshot
impl RefUnwindSafe for Snapshot
impl Send for Snapshot
impl Sync for Snapshot
impl Unpin for Snapshot
impl UnwindSafe for Snapshot
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
)