1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use Error;
use ;
/// A type alias for results that may contain a [`StimError`].
///
/// This is the standard return type for all fallible operations in the `stim`
/// crate. It is a convenience alias so that callers do not need to import
/// `StimError` separately when propagating errors with `?`.
///
/// # Examples
///
/// ```
/// fn parse_circuit(text: &str) -> stim::Result<stim::Circuit> {
/// text.parse::<stim::Circuit>()
/// .map_err(|e| stim::StimError::new(e.to_string()))
/// }
/// ```
pub type Result<T> = Result;
/// An error produced by the Stim library.
///
/// This is the unified error type for all fallible operations in the `stim`
/// crate. It wraps a human-readable message string describing what went wrong.
///
/// Most functions and methods in this crate return [`Result<T>`](crate::Result),
/// which is an alias for `std::result::Result<T, StimError>`. When an operation
/// fails -- for example because a circuit contains an invalid gate name, a
/// target index is out of range, a file cannot be read, or a stabilizer
/// operation is mathematically invalid -- the error message explains the cause.
///
/// `StimError` implements the standard [`Error`](std::error::Error) trait, so it
/// integrates smoothly with the Rust error-handling ecosystem (including
/// `anyhow`, `eyre`, and the `?` operator). It also converts automatically
/// from C++ exceptions raised by the underlying Stim C++ library via the
/// `From<cxx::Exception>` implementation.
///
/// # Examples
///
/// ```
/// let err = stim::StimError::new("invalid circuit syntax");
/// assert_eq!(err.message(), "invalid circuit syntax");
/// assert_eq!(err.to_string(), "invalid circuit syntax");
///
/// // StimError implements std::error::Error.
/// let dyn_err: Box<dyn std::error::Error> = Box::new(err);
/// assert_eq!(dyn_err.to_string(), "invalid circuit syntax");
/// ```