Skip to main content

Module error

Module error 

Source
Expand description

The error type of comnum.

Every fallible function returns Result<T>, whose error says what kind of mistake was made: an invalid configuration (a parameter out of its domain), inconsistent sizes, a numerical failure (a non-finite value, a singular system), a missing value in a simulation condition, or an input/output error.

The crates of layers 0 to 4 share this one enum, re-exported as comnum::Error, so that ? composes across blocks of different crates inside a simulation trial (see docs/adr/0003-shared-error-type.md).

§Examples

use comnum_core::{ensure, Error};
let err = ensure(false, || "order must be a power of two, got 6".into()).unwrap_err();
assert!(matches!(err, Error::Config(_)));
assert_eq!(err.context("qam").to_string(), "invalid configuration: qam: order must be a power of two, got 6");

Enums§

Error
The error of every fallible operation of comnum.

Functions§

ensure
Return Error::Config with the message of msg unless ok.
ensure_shape
Return Error::Shape with the message of msg unless ok (inconsistent lengths or shapes; ensure for a parameter outside its domain).
expect_len
Return Error::Shape unless a block of got elements has the want expected (what names the elements).
same_len
Return Error::Shape unless a == b (what names the two inputs).

Type Aliases§

Result
Result with the error type of comnum.