#[non_exhaustive]pub struct CommandError {
pub headline: String,
pub reason: Option<String>,
pub hint: Option<String>,
pub details: Option<String>,
pub user: bool,
}Expand description
Why a command failed, for people and for the record.
A handler that knows what to tell the user builds one
(CommandError::new, then reason,
hint, details); its user mark
says the headline is in the user’s words. A bare text (String,
&str) or an error (std::io::Error, a boxed error, anyhow’s
through CommandError::from_error) converts to one whose headline
is that text and whose user mark is off: shown to the user, it gets
a generic headline (“Export did not work”) and the text as its
details.
Its Display is the headline, then : and the reason when there is
one: a CommandError made from a text displays that text unchanged,
so code that prints or compares the old String errors keeps working.
use egui_pop_model::commands::CommandError;
let e = CommandError::from("connect: No route to host");
assert_eq!(e.to_string(), "connect: No route to host");
assert!(!e.user);
let e = CommandError::new("cloudy was not added")
.reason("The network found no route to it.")
.hint("Check that cloudy is on and on the same network.")
.details("connect 192.168.1.12:7443: No route to host (os error 113)");
assert!(e.user);
assert_eq!(e.to_string(), "cloudy was not added: The network found no route to it.");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.headline: StringWhat failed: in the user’s words when user, else the technical
text it was made from.
reason: Option<String>Why, in the user’s words, when known.
hint: Option<String>What the user can do about it.
details: Option<String>The technical chain (an error and its sources, one per line).
user: boolWhether the headline is written for the user (false: a technical
text, shown under a generic headline).
Implementations§
Source§impl CommandError
impl CommandError
Sourcepub fn new(headline: impl Into<String>) -> CommandError
pub fn new(headline: impl Into<String>) -> CommandError
A failure told in the user’s words.
Sourcepub fn technical(text: impl Into<String>) -> CommandError
pub fn technical(text: impl Into<String>) -> CommandError
A technical failure (user off): the text as its headline.
Sourcepub fn from_error(err: &(dyn Error + 'static)) -> CommandError
pub fn from_error(err: &(dyn Error + 'static)) -> CommandError
An error and its sources: its text as the (technical) headline, the whole chain, one per line, as the details.
Sourcepub fn reason(self, reason: impl Into<String>) -> CommandError
pub fn reason(self, reason: impl Into<String>) -> CommandError
Why (left out when blank).
Sourcepub fn hint(self, hint: impl Into<String>) -> CommandError
pub fn hint(self, hint: impl Into<String>) -> CommandError
What to do (left out when blank).
Sourcepub fn details(self, details: impl Into<String>) -> CommandError
pub fn details(self, details: impl Into<String>) -> CommandError
The technical chain (left out when blank).
Trait Implementations§
Source§impl Clone for CommandError
impl Clone for CommandError
Source§fn clone(&self) -> CommandError
fn clone(&self) -> CommandError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CommandError
impl Debug for CommandError
Source§impl Default for CommandError
impl Default for CommandError
Source§fn default() -> CommandError
fn default() -> CommandError
Source§impl<'de> Deserialize<'de> for CommandError
impl<'de> Deserialize<'de> for CommandError
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CommandError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CommandError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for CommandError
impl Display for CommandError
Source§impl From<&String> for CommandError
impl From<&String> for CommandError
Source§fn from(text: &String) -> CommandError
fn from(text: &String) -> CommandError
Source§impl From<&str> for CommandError
impl From<&str> for CommandError
Source§fn from(text: &str) -> CommandError
fn from(text: &str) -> CommandError
Source§impl From<Error> for CommandError
impl From<Error> for CommandError
Source§fn from(err: Error) -> CommandError
fn from(err: Error) -> CommandError
Source§impl From<Error> for CommandError
impl From<Error> for CommandError
Source§fn from(err: Error) -> CommandError
fn from(err: Error) -> CommandError
Source§impl From<String> for CommandError
impl From<String> for CommandError
Source§fn from(text: String) -> CommandError
fn from(text: String) -> CommandError
Source§impl PartialEq for CommandError
impl PartialEq for CommandError
Source§impl Serialize for CommandError
impl Serialize for CommandError
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for CommandError
impl StructuralPartialEq for CommandError
Auto Trait Implementations§
impl Freeze for CommandError
impl RefUnwindSafe for CommandError
impl Send for CommandError
impl Sync for CommandError
impl Unpin for CommandError
impl UnsafeUnpin for CommandError
impl UnwindSafe for CommandError
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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