Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
    Const(Ternary),
    Var(String),
    Not(Box<Expr>),
    And(Box<Expr>, Box<Expr>),
    Or(Box<Expr>, Box<Expr>),
    Xor(Box<Expr>, Box<Expr>),
    Implies(Box<Expr>, Box<Expr>),
    Equiv(Box<Expr>, Box<Expr>),
}
Expand description

表达式节点。

Variants§

§

Const(Ternary)

逻辑常量。

§

Var(String)

变量引用。

§

Not(Box<Expr>)

否定 ¬a。

§

And(Box<Expr>, Box<Expr>)

与 a ∧ b。

§

Or(Box<Expr>, Box<Expr>)

或 a ∨ b。

§

Xor(Box<Expr>, Box<Expr>)

强加法 a ⊕ b。

§

Implies(Box<Expr>, Box<Expr>)

蕴含 a ⇒ b(右结合)。

§

Equiv(Box<Expr>, Box<Expr>)

等价 a ≡ b。

Implementations§

Source§

impl Expr

Source

pub fn and(a: Expr, b: Expr) -> Self

构造与节点。

Source

pub fn or(a: Expr, b: Expr) -> Self

构造或节点。

Source

pub fn logical_not(a: Expr) -> Self

构造否定节点。

命名为 logical_not 而非 not,避免与 std::ops::Not::not 混淆。

Source

pub fn xor(a: Expr, b: Expr) -> Self

构造强加法节点。

Source

pub fn implies(a: Expr, b: Expr) -> Self

构造蕴含节点。

Source

pub fn equiv(a: Expr, b: Expr) -> Self

构造等价节点。

Source

pub fn try_var(name: impl Into<String>) -> Result<Self, VarNameError>

校验并构造变量节点。

Expr::Var 的字段是公开的,直接构造可以塞进空白、运算符或常量 token; 这类 AST 的 Display 不保证能被 Parser 无损解析回来。

Source

pub const fn is_unknown_const(&self) -> bool

是否为常量 Unknown。

Source

pub fn variables(&self) -> Vec<String>

收集表达式中出现的全部变量名(保持首次出现顺序)。

迭代实现,不对任意深的树递归。

Source

pub fn node_count(&self) -> usize

节点总数(用于复杂度统计)。迭代实现。

Source

pub fn depth(&self) -> usize

树的最大深度(根为 1)。迭代实现。

Source

pub fn to_infix(&self) -> String

渲染为规范的中缀记法(带全角运算符),用于展示与化简输出。

递归实现;对未经过预算检查的手工深树,请先调用 check_expr。任意 Expr::Var 的文本 往返由 Expr::try_var 约束,而不是由 Display 本身保证。

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Expr

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Expr

Source§

impl Hash for Expr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Expr

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.