gix_actor/lib.rs
1//! This crate provides ways of identifying an actor within the git repository both in shared and mutable variants.
2//!
3//! ## Feature Flags
4#![cfg_attr(
5 all(doc, feature = "document-features"),
6 doc = ::document_features::document_features!()
7)]
8#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
9#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
10
11/// The re-exported `bstr` crate.
12///
13/// For convenience to allow using `bstr` without adding it to own cargo manifest.
14pub use bstr;
15use bstr::{BStr, BString};
16/// The re-exported `gix-date` crate.
17///
18/// For convenience to allow using `gix-date` without adding it to own cargo manifest.
19pub use gix_date as date;
20
21mod identity;
22///
23pub mod signature;
24
25/// A person with name and email.
26#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
27#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
28pub struct Identity {
29 /// The actors name, potentially with whitespace as parsed.
30 ///
31 /// Use [IdentityRef::trim()] or trim manually to be able to clean it up.
32 pub name: BString,
33 /// The actor's email, potentially with whitespace and garbage as parsed.
34 ///
35 /// Use [IdentityRef::trim()] or trim manually to be able to clean it up.
36 pub email: BString,
37}
38
39/// A person with name and email, as reference.
40#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub struct IdentityRef<'a> {
43 /// The actors name, potentially with whitespace as parsed.
44 ///
45 /// Use [IdentityRef::trim()] or trim manually to be able to clean it up.
46 #[cfg_attr(feature = "serde", serde(borrow))]
47 pub name: &'a BStr,
48 /// The actor's email, potentially with whitespace and garbage as parsed.
49 ///
50 /// Use [IdentityRef::trim()] or trim manually to be able to clean it up.
51 pub email: &'a BStr,
52}
53
54/// A mutable signature that is created by an actor at a certain time.
55///
56/// Note that this is not a cryptographical signature.
57#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct Signature {
60 /// The actors name, potentially with whitespace as parsed.
61 ///
62 /// Use [SignatureRef::trim()] or trim manually to be able to clean it up.
63 pub name: BString,
64 /// The actor's email, potentially with whitespace and garbage as parsed.
65 ///
66 /// Use [SignatureRef::trim()] or trim manually to be able to clean it up.
67 pub email: BString,
68 /// The time stamp at which the signature is performed.
69 pub time: date::Time,
70}
71
72/// An immutable signature that is created by an actor at a certain time.
73///
74/// All of its fields are references to the backing buffer to allow lossless
75/// round-tripping, as decoding the `time` field could be a lossy transformation.
76///
77/// Note that this is not a cryptographical signature.
78#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct SignatureRef<'a> {
81 /// The actors name, potentially with whitespace as parsed.
82 ///
83 /// Use [SignatureRef::trim()] or trim manually for cleanup.
84 #[cfg_attr(feature = "serde", serde(borrow))]
85 pub name: &'a BStr,
86 /// The actor's email, potentially with whitespace and garbage as parsed.
87 ///
88 /// Use [SignatureRef::trim()] or trim manually for cleanup.
89 pub email: &'a BStr,
90 /// The timestamp at which the signature was performed,
91 /// potentially malformed due to lenient parsing.
92 ///
93 /// Use [`SignatureRef::time()`] to decode.
94 pub time: &'a str,
95}