pub struct CandidateError {
pub failure: CandidateFailure,
pub message: String,
}Expand description
What:
One candidate failure:
its cause and a complete explanation.
String is a heap-allocated,
growable UTF-8 buffer this struct owns.
Sibling the reader might expect:
&str,
a borrowed view that owns nothing.
Why:
The error outlives the formatted text built at the failure site,
so a
borrowed &str would dangle.
Messages never contain file content or
pathnames:
a pathname can itself be a forbidden string.
In TS you’d write (pseudocode):
class CandidateError extends Error { failure: CandidateFailure; message: string }Fields§
§failure: CandidateFailureClosed cause callers branch on.
message: StringComplete diagnostic naming the Git operation and what to check.
Implementations§
Source§impl CandidateError
What:
impl CandidateError { ... } attaches functions to the struct,
like class statics.
Why:
Failure sites keep their condition next to its user-facing explanation.
impl CandidateError
What:
impl CandidateError { ... } attaches functions to the struct,
like class statics.
Why:
Failure sites keep their condition next to its user-facing explanation.
In TS you’d write (pseudocode):
new CandidateError(failure, message);Sourcepub fn new(failure: CandidateFailure, message: &str) -> CandidateError
pub fn new(failure: CandidateFailure, message: &str) -> CandidateError
What:
Build an error from a cause and borrowed text.
&str lends the caller’s
bytes;
String::from copies them into storage the error owns.
Why:
Messages are usually format! temporaries that end with the caller’s statement.
In TS you’d write (pseudocode):
constructor(failure: CandidateFailure, message: string) { super(message); }Trait Implementations§
Source§impl Clone for CandidateError
impl Clone for CandidateError
Source§impl Debug for CandidateError
impl Debug for CandidateError
Source§impl Display for CandidateError
What:
impl std::fmt::Display for CandidateError supplies Rust’s “print me” interface.
:: walks module paths,
like std.fmt.Display would in TS.
Why:
The executable writes the message with ordinary formatting,
not field access.
impl Display for CandidateError
What:
impl std::fmt::Display for CandidateError supplies Rust’s “print me” interface.
:: walks module paths,
like std.fmt.Display would in TS.
Why:
The executable writes the message with ordinary formatting,
not field access.
In TS you’d write (pseudocode):
toString(): string { return this.message; }Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
What:
&self borrows this error read-only;
&mut lends the formatter for writing;
'_ is an unnamed lifetime the compiler fills in.
Why:
Formatting writes into the caller’s buffer without allocating another string.
In TS you’d write (pseudocode):
format(out: Writer): void { out.write(this.message); }impl Eq for CandidateError
Source§impl Error for CandidateError
What:
An empty impl marks the type as a standard error value.
Why:
Generic error handling can carry it without converting it to a bare string.
impl Error for CandidateError
What:
An empty impl marks the type as a standard error value.
Why:
Generic error handling can carry it without converting it to a bare string.
In TS you’d write (pseudocode):
// `extends Error` already provides this in TypeScript.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for CandidateError
impl PartialEq for CandidateError
impl StructuralPartialEq for CandidateError
Auto Trait Implementations§
impl Freeze for CandidateError
impl RefUnwindSafe for CandidateError
impl Send for CandidateError
impl Sync for CandidateError
impl Unpin for CandidateError
impl UnsafeUnpin for CandidateError
impl UnwindSafe for CandidateError
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> ErrorExt for T
impl<T> ErrorExt for T
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