pub struct ExprCompare {
pub node_index: AtomicNodeIndex,
pub range: TextRange,
pub ops: Box<[CmpOp]>,
pub operands: Box<[Expr]>,
pub runtime_comparators: Option<Vec<Option<Expr>>>,
}Expand description
A comparison or chain of comparisons.
operands contains all operands in source order, including the leftmost operand.
For example, a < b <= c has operands [a, b, c] and operators [Lt, LtE].
There is at least one operator, and operands.len() == ops.len() + 1.
See also Compare.
Fields§
§node_index: AtomicNodeIndex§range: TextRange§ops: Box<[CmpOp]>§operands: Box<[Expr]>§runtime_comparators: Option<Vec<Option<Expr>>>Implementations§
Source§impl ExprCompare
impl ExprCompare
Sourcepub fn first_operand(&self) -> &Expr
pub fn first_operand(&self) -> &Expr
Returns the initial operand (a in a < b <= c).
§Panics
Panics if there are no operands. The parser always produces at least two operands, synthesizing an invalid name expression for a missing operand during error recovery.
Sourcepub fn second_operand(&self) -> &Expr
pub fn second_operand(&self) -> &Expr
Returns the right operand of the first comparison (b in a < b <= c).
§Panics
Panics if there are fewer than two operands. See Self::first_operand.
Sourcepub fn first_operator(&self) -> CmpOp
pub fn first_operator(&self) -> CmpOp
Returns the first comparison operator (< in a < b <= c).
§Panics
Panics if there are no operators. The parser always produces at least one operator.
Sourcepub fn comparators(&self) -> &[Expr]
pub fn comparators(&self) -> &[Expr]
Returns all operands after the initial operand ([b, c] in a < b <= c).
§Panics
Panics if there are no operands. See Self::first_operand.
Sourcepub fn as_single(&self) -> Option<(&Expr, &CmpOp, &Expr)>
pub fn as_single(&self) -> Option<(&Expr, &CmpOp, &Expr)>
Returns (left, operator, right) if there is exactly one operator and two operands.
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = (&Expr, &CmpOp, &Expr)> + ExactSizeIterator
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = (&Expr, &CmpOp, &Expr)> + ExactSizeIterator
Iterates over each comparison as (left, operator, right).
For a < b <= c, yields (a, <, b) followed by (b, <=, c).
Trait Implementations§
Source§impl Clone for ExprCompare
impl Clone for ExprCompare
Source§impl Debug for ExprCompare
impl Debug for ExprCompare
Source§impl<'a> From<&'a ExprCompare> for ExprRef<'a>
impl<'a> From<&'a ExprCompare> for ExprRef<'a>
Source§fn from(node: &'a ExprCompare) -> Self
fn from(node: &'a ExprCompare) -> Self
Source§impl<'a> From<&'a ExprCompare> for AnyNodeRef<'a>
impl<'a> From<&'a ExprCompare> for AnyNodeRef<'a>
Source§fn from(node: &'a ExprCompare) -> AnyNodeRef<'a>
fn from(node: &'a ExprCompare) -> AnyNodeRef<'a>
Source§impl From<ExprCompare> for Expr
impl From<ExprCompare> for Expr
Source§fn from(node: ExprCompare) -> Self
fn from(node: ExprCompare) -> Self
Source§impl HasNodeIndex for ExprCompare
impl HasNodeIndex for ExprCompare
Source§fn node_index(&self) -> &AtomicNodeIndex
fn node_index(&self) -> &AtomicNodeIndex
AtomicNodeIndex for this node.Source§impl PartialEq for ExprCompare
impl PartialEq for ExprCompare
Source§impl Ranged for ExprCompare
impl Ranged for ExprCompare
impl StructuralPartialEq for ExprCompare
Source§impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a ExprCompare
impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a ExprCompare
Auto Trait Implementations§
impl !Freeze for ExprCompare
impl RefUnwindSafe for ExprCompare
impl Send for ExprCompare
impl Sync for ExprCompare
impl Unpin for ExprCompare
impl UnsafeUnpin for ExprCompare
impl UnwindSafe for ExprCompare
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more