[−][src]Enum qasmsim::error::QasmSimError
Types of errors in QasmSim. QasmSim errors contain information about the error and the location in the source code where the error happens.
QasmSimError
instances can be printed. They refer to the source code and
try to provide contextual information for fixing the problem.
Conversion between ParseError
, RuntimeError
and LinkerError
is
possible thanks to the trait From
is defined for the pair
(&'source str, T)
(see alias SrcAndErr
) for all the errors listed
above.
Examples
The error type of [simulate()
] is RuntimeError
.
RuntimeError
is a sourceless error in the sense it does not relate with
the concrete source code beyond the location in the AST at which the error
happens.
You can use map_err
for for capturing the error and converting it
into a QasmSimError
from its pairing with the source.
use qasmsim::{QasmSimError, parse_and_link, simulate}; let source = r#" OPENQASM 2.0; qreg q[2]; CX q[1], q[2]; // Notice we are indexing out of bounds here. "#; let program = parse_and_link(source)?; let runtime_error = simulate(&program).expect_err("Index out of bounds"); let qasmsim_error = QasmSimError::from((source, runtime_error));
Variants (Non-exhaustive)
UnknownError(String)
A generic unknown error.
Found an invalid token at some position.
Fields of InvalidToken
source: &'src str
Line source.
lineno: usize
Line number.
startpos: usize
Position inside the line (0-based) where the invalid token starts.
endpos: Option<usize>
Position inside the line (0-based) where the invalid token ends.
token: Option<Tok>
Token found.
expected: Vec<String>
A list of expected tokens.
Found an unexpected end of file.
Fields of UnexpectedEOF
source: &'src str
Line source.
lineno: usize
Line number.
startpos: usize
Position inside the line (0-based) where the invalid token starts.
endpos: Option<usize>
Position inside the line (0-based) where the invalid token ends.
token: Option<Tok>
Token found.
expected: Vec<String>
A list of expected tokens.
Found an unexpected token.
Fields of UnexpectedToken
source: &'src str
Line source.
lineno: usize
Line number.
startpos: usize
Position inside the line (0-based) where the invalid token starts.
endpos: Option<usize>
Position inside the line (0-based) where the invalid token ends.
token: Option<Tok>
Token found.
expected: Vec<String>
A list of expected tokens.
Found a redefinition of a register.
Fields of RedefinitionError
The unability of linking a library.
Fields of LibraryNotFound
Use of register index that does not fit the register size.
Fields of IndexOutOfBounds
Use of an unknown/undeclared symbol.
Fields of SymbolNotFound
The attempt of applying an operation passing the wrong number of parameters.
Fields of WrongNumberOfParameters
Use of a gate not previously defined.
Fields of UndefinedGate
Found an unexpected type of value.
Fields of TypeMismatch
Attempt of applying an operation to different sizes registers.
Fields of RegisterSizeMismatch
Trait Implementations
impl<'src> Clone for QasmSimError<'src>
[src]
fn clone(&self) -> QasmSimError<'src>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'src> Debug for QasmSimError<'src>
[src]
impl<'_> Display for QasmSimError<'_>
[src]
impl<'src> Eq for QasmSimError<'src>
[src]
impl<'_> Error for QasmSimError<'_>
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
fn backtrace(&self) -> Option<&Backtrace>
[src]
fn description(&self) -> &str
1.0.0[src]
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl<'src> From<(&'src str, LinkerError)> for QasmSimError<'src>
[src]
fn from(source_and_error: SrcAndErr<'src, LinkerError>) -> Self
[src]
impl<'src> From<(&'src str, ParseError<Location, Tok, LexicalError<Location>>)> for QasmSimError<'src>
[src]
fn from(src_and_err: SrcAndErr<'src, ParseError>) -> Self
[src]
impl<'src> From<(&'src str, RuntimeError)> for QasmSimError<'src>
[src]
fn from(source_and_error: SrcAndErr<'src, RuntimeError>) -> Self
[src]
impl<'_> From<String> for QasmSimError<'_>
[src]
impl<'src> Hash for QasmSimError<'src>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'src> PartialEq<QasmSimError<'src>> for QasmSimError<'src>
[src]
fn eq(&self, other: &QasmSimError<'src>) -> bool
[src]
fn ne(&self, other: &QasmSimError<'src>) -> bool
[src]
impl<'src> StructuralEq for QasmSimError<'src>
[src]
impl<'src> StructuralPartialEq for QasmSimError<'src>
[src]
Auto Trait Implementations
impl<'src> RefUnwindSafe for QasmSimError<'src>
impl<'src> Send for QasmSimError<'src>
impl<'src> Sync for QasmSimError<'src>
impl<'src> Unpin for QasmSimError<'src>
impl<'src> UnwindSafe for QasmSimError<'src>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,