pub struct ConfigError {
pub message: String,
}Expand description
What:
ConfigError owns the explanation of one rejected configuration.
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 parsed document and the temporary formatted text,
so a borrowed &str would dangle;
String keeps the bytes alive.
In TS you’d write (pseudocode):
class ConfigError extends Error { readonly message: string }Fields§
§message: StringComplete diagnostic naming the affected key or file and the accepted values.
Implementations§
Source§impl ConfigError
What:
impl ConfigError { ... } attaches functions to the struct,
like class statics.
Why:
Validation sites keep their condition next to its user-facing explanation.
impl ConfigError
What:
impl ConfigError { ... } attaches functions to the struct,
like class statics.
Why:
Validation sites keep their condition next to its user-facing explanation.
In TS you’d write (pseudocode):
new ConfigError(message);Sourcepub fn new(message: &str) -> ConfigError
pub fn new(message: &str) -> ConfigError
What:
Build an error from 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(message: string) { super(message); }Trait Implementations§
Source§impl Clone for ConfigError
impl Clone for ConfigError
Source§impl Debug for ConfigError
impl Debug for ConfigError
Source§impl Display for ConfigError
What:
impl std::fmt::Display for ConfigError 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 ConfigError
What:
impl std::fmt::Display for ConfigError 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 ConfigError
Source§impl Error for ConfigError
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 ConfigError
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 ConfigError
impl PartialEq for ConfigError
impl StructuralPartialEq for ConfigError
Auto Trait Implementations§
impl Freeze for ConfigError
impl RefUnwindSafe for ConfigError
impl Send for ConfigError
impl Sync for ConfigError
impl Unpin for ConfigError
impl UnsafeUnpin for ConfigError
impl UnwindSafe for ConfigError
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