pub struct EventPath { /* private fields */ }Expand description
What:
One path as events report it.
The fields are private,
so the only ways to build
one are the two constructors,
and exact is present exactly when the bytes
were not UTF-8.
#[derive(...)] generates cloning,
debug printing and ==.
Why:
A reader must be able to rely on “no pathBytes means path is the exact name”.
In TS you’d write (pseudocode):
type EventPath = { readonly text: string; readonly exact?: Uint8Array };Implementations§
Source§impl EventPath
What:
impl EventPath { ... } attaches the constructors and the two reads.
Why:
The invariant between the two fields is kept in one place.
impl EventPath
What:
impl EventPath { ... } attaches the constructors and the two reads.
Why:
The invariant between the two fields is kept in one place.
In TS you’d write (pseudocode):
class EventPath { static fromGitBytes(bytes) {} static display(text) {} }Sourcepub fn from_git_bytes(bytes: &[u8]) -> EventPath
pub fn from_git_bytes(bytes: &[u8]) -> EventPath
What:
The event form of a pathname exactly as Git printed it.
&[u8] borrows the
bytes;
String::from_utf8_lossy replaces each invalid sequence by U+FFFD.
Why:
A UTF-8 name is its own exact form and gets no extra field;
any other name
keeps its bytes,
because different names can share one replaced text.
In TS you’d write (pseudocode):
static fromGitBytes(bytes: Uint8Array): EventPath;Sourcepub fn display(text: &str) -> EventPath
pub fn display(text: &str) -> EventPath
What:
A path whose event form is text only.
&str borrows the text.
Why:
A constant name,
or the scanner’s masked display of a name,
is already text;
the masked display must never carry the bytes it masks.
In TS you’d write (pseudocode):
static display(text: string): EventPath;Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
What:
The readable text of the path.
&str borrows it from the record.
Why:
Every event prints it as path,
whatever else it prints.
In TS you’d write (pseudocode):
get text(): string;Sourcepub fn exact(&self) -> Option<&[u8]>
pub fn exact(&self) -> Option<&[u8]>
What:
The exact bytes,
only when they are not UTF-8.
Option<&[u8]> lends them or
says there are none.
Why:
Rendering adds pathBytes exactly when this is present.
In TS you’d write (pseudocode):
get exact(): Uint8Array | undefined;Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
What: The bytes of the name: the exact ones when kept, else the text’s UTF-8 bytes. Why: A list of paths that holds one name that is not UTF-8 lists the bytes of every name, so its entries line up with the readable list one for one.
In TS you’d write (pseudocode):
get bytes(): Uint8Array { return this.exact ?? new TextEncoder().encode(this.text); }Trait Implementations§
impl Eq for EventPath
impl StructuralPartialEq for EventPath
Auto Trait Implementations§
impl Freeze for EventPath
impl RefUnwindSafe for EventPath
impl Send for EventPath
impl Sync for EventPath
impl Unpin for EventPath
impl UnsafeUnpin for EventPath
impl UnwindSafe for EventPath
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more