Struct gix_mailmap::Snapshot

source ·
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

source

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.

source

pub fn new<'a>(entries: impl IntoIterator<Item = Entry<'a>>) -> Self

Create a new instance from entries.

These can be obtained using crate::parse().

source

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.

source

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).

source

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.

source

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.

source

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.

source

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§

source§

impl Clone for Snapshot

source§

fn clone(&self) -> Snapshot

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Snapshot

source§

fn default() -> Snapshot

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.