Expand description
Typed, side-effect-free runtime classical expressions.
Expressions read ClassicalVar and ClassicalValue handles and combine
them into typed runtime values. They do not measure qubits, write classical
storage, or transfer control. Control-flow statements consume these
expressions in a later layer.
Build expressions with the typed constructors on ClassicalExpr.
ClassicalVar and ClassicalValue handles can be converted directly
into expressions, so var.expr(), ClassicalExpr::from(var), and passing a
handle to a try_* builder are equivalent expression sources. Leaf
constructors such as ClassicalExpr::bool_literal and
ClassicalExpr::bit_literal are infallible. Constructors that validate
operand types return Result<ClassicalExpr, CircuitError>; the fallible
logical builders use a try_ prefix, for example
ClassicalExpr::try_not, ClassicalExpr::try_and,
ClassicalExpr::try_or, and ClassicalExpr::try_xor.
Prefer Rust bit operators when the expression types are already known:
!source, lhs & rhs, lhs | rhs, and lhs ^ rhs. Each source may be a
ClassicalExpr, ClassicalVar, or ClassicalValue. These operator
overloads panic if the operands are not matching Bool or matching Bit
expressions, because the standard operator traits cannot return Result.
Use the fallible try_* builders when invalid input should be reported as
CircuitError instead of a panic.
use cqlib_core::circuit::{CircuitId, ClassicalExpr, ClassicalType, ClassicalVar};
let cid = CircuitId::new();
let a = ClassicalVar::new(cid, 0, ClassicalType::Bool);
let b = ClassicalVar::new(cid, 1, ClassicalType::Bool);
let condition = !a & b;
assert_eq!(condition.ty(), ClassicalType::Bool);
let checked = ClassicalExpr::try_and(ClassicalExpr::try_not(a)?, b)?;
assert_eq!(checked.ty(), ClassicalType::Bool);Structs§
- Classical
Expr - A typed, side-effect-free runtime classical expression.
- Classical
Expr Node - Typed node stored inside a
ClassicalExpr.
Enums§
- Classical
Binary Op - Binary operators for boolean and bit expressions.
- Classical
Cast - Explicit casts between classical expression types.
- Classical
Compare Op - Comparison operators for classical expressions.
- Classical
Expr Kind - Public node kind for inspecting a
ClassicalExprAST. - Classical
Unary Op - Unary operators for classical expressions.