Struct alloc_data::err::ErrorCxt
source · [−]pub struct ErrorCxt { /* private fields */ }
Expand description
Error context, a shallow interface over a global list of errors.
The point of this type is to provide a memory of the errors from the global list of errors seen
so far. There’s no point in using this just to register errors, use err::register
instead.
This type is used by the server and the different client-sockets because they need to report errors.
Examples
let errors = vec![
("error 0", false),
("error 1", false),
("error 2", true),
("error 3", false),
("error 4", true),
];
let mut cnt = 0;
macro_rules! check {
() => {
|err: &str, is_fatal| {
assert_eq!(err, errors[cnt].0);
assert_eq!(is_fatal, errors[cnt].1);
cnt += 1
}
};
}
let mut cxt = ErrorCxt::new();
cxt.register(errors[0].0, errors[0].1);
cxt.register(errors[1].0, errors[1].1);
// Applies `check` to the two errors registered so far.
let (err_count, fatal) = cxt.new_errors_do(check!());
assert!(!fatal);
assert_eq!(err_count, 2);
assert_eq!(cnt, 2);
// Applies `check` to nothing, there are no new errors.
let (err_count, fatal) = cxt.new_errors_do(check!());
assert!(!fatal);
assert_eq!(err_count, 0);
assert_eq!(cnt, 2);
cxt.register(errors[2].0, errors[2].1);
cxt.register(errors[3].0, errors[3].1);
// Applies `check` to the two new errors.
let (err_count, fatal) = cxt.new_errors_do(check!());
assert!(fatal);
assert_eq!(err_count, 2);
assert_eq!(cnt, 4);
// Registering from the `err` module is fine too.
err::register(errors[4].0, errors[4].1);
// Applies `check` to the one new error.
let (err_count, fatal) = cxt.new_errors_do(check!());
assert!(fatal);
assert_eq!(err_count, 1);
assert_eq!(cnt, 5);
Implementations
sourceimpl ErrorCxt
impl ErrorCxt
sourcepub fn register_non_fatal(&self, e: impl Into<Error>)
pub fn register_non_fatal(&self, e: impl Into<Error>)
Registers a non-fatal error in the global list of errors.
See the type-level documentation for examples.
sourcepub fn register_fatal(&self, e: impl Into<Error>)
pub fn register_fatal(&self, e: impl Into<Error>)
Registers a fatal error in the global list of errors.
See the type-level documentation for examples.
sourcepub fn register(&self, e: impl Into<Error>, fatal: bool)
pub fn register(&self, e: impl Into<Error>, fatal: bool)
Registers an error in the global list of errors.
See the type-level documentation for examples.
sourcepub fn new_errors_do(&mut self, action: impl FnMut(&str, bool)) -> (usize, bool)
pub fn new_errors_do(&mut self, action: impl FnMut(&str, bool)) -> (usize, bool)
Applies an action to the new errors in the global list of errors.
Returns the number of new errors to which action
was applied.
NB: errors only appear once across calls. So when action(e_i)
runs, future calls
to this function will never run action(e_i)
again.
See the type-level documentation for examples.
sourcepub fn new_errors_try<E>(
&mut self,
action: impl FnMut(&str, bool) -> Result<(), E>
) -> Result<(usize, bool), E>
pub fn new_errors_try<E>(
&mut self,
action: impl FnMut(&str, bool) -> Result<(), E>
) -> Result<(usize, bool), E>
Applies an action that can fail to the new errors in the global list of errors.
Returns the number of new errors to which action
was applied.
NB: errors only appear once across calls. So when action(e_i)
runs, future calls
to this function will never run action(e_i)
again.
See the type-level documentation for examples.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ErrorCxt
impl Send for ErrorCxt
impl !Sync for ErrorCxt
impl Unpin for ErrorCxt
impl UnwindSafe for ErrorCxt
Blanket Implementations
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
type Err = NoError
type Err = NoError
The error type produced by a failed conversion.
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> ConvUtil for T
impl<T> ConvUtil for T
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
Approximate the subject to a given type with the default scheme.
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Approximate the subject to a given type with a specific scheme.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
impl<Src> ValueFrom<Src> for Src
impl<Src> ValueFrom<Src> for Src
type Err = NoError
type Err = NoError
The error type produced by a failed conversion.
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
Convert the given value into an exactly equivalent representation.
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
type Err = <Dst as ValueFrom<Src>>::Err
type Err = <Dst as ValueFrom<Src>>::Err
The error type produced by a failed conversion.
fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
Convert the subject into an exactly equivalent representation.