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

Constructor.

Registers a non-fatal error in the global list of errors.

See the type-level documentation for examples.

Registers a fatal error in the global list of errors.

See the type-level documentation for examples.

Registers an error in the global list of errors.

See the type-level documentation for examples.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The error type produced by a failed conversion.

Convert the given value into an approximately equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an approximately equivalent representation.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Approximate the subject with the default scheme.

Approximate the subject with a specific scheme.

Approximate the subject to a given type with the default scheme.

Approximate the subject to a given type with a specific scheme.

Convert the subject to a given type.

Attempt to convert the subject to a given type.

Attempt a value conversion of the subject to a given type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The error type produced by a failed conversion.

Convert the given value into the subject type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the subject into the destination type.

The type returned in the event of a conversion error.

Performs the conversion.

The error type produced by a failed conversion.

Convert the given value into an exactly equivalent representation.

The error type produced by a failed conversion.

Convert the subject into an exactly equivalent representation.