Skip to main content

Signature

Struct Signature 

Source
pub struct Signature {
    pub name: ByteString,
    pub email: ByteString,
    pub time: GitTime,
    pub raw: Vec<u8>,
}
Expand description

A typed parse-view of a git identity line (Name <email> <secs> <tz>) as found on a commit’s author/committer or a tag’s tagger header.

This is a read-only lens over bytes that are stored and re-serialized verbatim elsewhere (see Signature::raw). It exists so callers can read the typed name/email/time of an identity without re-implementing git’s ident-splitting rules, not as a storage format: the object model keeps the original raw bytes as its source of truth, and round-tripping through this view is byte-exact precisely because the raw line is retained alongside the parsed fields (see Signature::to_ident_bytes).

Parse one with Signature::from_ident_line. The time’s timezone preserves git’s distinction between +0000 (UTC) and -0000 (a sentinel git writes to mean “timezone unknown”); see GitTime.

Fields§

§name: ByteString

The identity’s name: the bytes before the < that opens the email, with one trailing space (the separator) removed. May be empty.

§email: ByteString

The identity’s email: the bytes between the < and > delimiters. May be empty.

§time: GitTime

The commit/authorship time and its timezone offset.

§raw: Vec<u8>

The exact original ident-line bytes this view was parsed from, retained so Signature::to_ident_bytes can reproduce the input byte-for-byte regardless of any non-canonical whitespace or formatting it contained.

Implementations§

Source§

impl Signature

Source

pub fn from_ident_line(line: &[u8]) -> Option<Self>

Parse a raw git identity line (Name <email> <unix-secs> <tz>) into a typed view, returning None when the bytes do not form a well-formed identity.

The splitting mirrors git’s own split_ident_line: the email is the run of bytes between the last < and the first following >; the name is everything before that < (one separating space is dropped); after the > come a space, the decimal Unix timestamp, a space, and the timezone token. The name and email may legitimately be empty, but a missing </> pair, a non-numeric timestamp, or a malformed timezone token all yield None rather than a lossy guess — this is a best-effort parse that never panics. The original bytes are retained in Signature::raw so the parsed view re-serializes byte-identically.

Source

pub fn to_ident_bytes(&self) -> Vec<u8>

Reproduce the original identity-line bytes.

This returns Signature::raw verbatim, so for any line that Signature::from_ident_line accepted, from_ident_line(line)? .to_ident_bytes() == line holds byte-for-byte — including the -0000 timezone and any non-canonical spacing the source contained.

Source

pub fn to_canonical_ident_bytes(&self) -> Vec<u8>

Re-derive the canonical ident line from the parsed fields alone (name <email> secs tz), ignoring Signature::raw.

For an identity in git’s canonical form this equals Signature::to_ident_bytes; it differs only when the source line carried non-canonical whitespace. Callers wanting byte-exact reproduction should use Signature::to_ident_bytes; this is provided for constructing a normalized line from typed parts.

Trait Implementations§

Source§

impl Clone for Signature

Source§

fn clone(&self) -> Signature

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Signature

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Signature

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Renders the original ident line (lossy only for bytes that are not valid UTF-8, which are replaced with U+FFFD). Use Signature::to_ident_bytes for the exact bytes.

Source§

impl Eq for Signature

Source§

impl PartialEq for Signature

Source§

fn eq(&self, other: &Signature) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Signature

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.