Enum LogicalExpression

Source
pub enum LogicalExpression<Condition> {
    And(Vec<LogicalExpression<Condition>>),
    Or(Vec<LogicalExpression<Condition>>),
    Condition(Condition),
}
Expand description

Represents a logical expression with conditions combined using AND and OR operators.

Variants§

§

And(Vec<LogicalExpression<Condition>>)

Represents a logical AND operation on a list of logical expressions.

§

Or(Vec<LogicalExpression<Condition>>)

Represents a logical OR operation on a list of logical expressions.

§

Condition(Condition)

Represents a single condition in the logical expression.

Implementations§

Source§

impl<C: FromStr> LogicalExpression<C>

Source

pub fn parse(s: &str) -> Result<Self, ParseError<<C as FromStr>::Err>>

Parses a logical expression from a string.

Returns a Result containing the parsed LogicalExpression if successful, or a ParseError if an error occurred during parsing.

Examples found in repository?
examples/example.rs (line 4)
3fn main() {
4    let expression: LogicalExpression<String> = LogicalExpression::parse("a & (b | c)").unwrap();
5    let expanded = expression.expand();
6    println!("{expanded:?}");
7}
Source§

impl<C> LogicalExpression<C>

Source

pub fn parse_with<F, E>( s: &str, parse_condition: F, ) -> Result<Self, ParseError<E>>
where F: FnMut(&str) -> Result<C, E>,

Parses a logical expression from a string using a custom parsing function.

The parse_condition function is used to parse individual conditions from string slices.

Returns a Result containing the parsed LogicalExpression if successful, or a ParseError if an error occurred during parsing.

Source

pub fn parse_with_expression<F, E>( s: &str, parse_expression: F, ) -> Result<Self, ParseError<E>>
where F: FnMut(&str) -> Result<Self, E>,

Parses a logical expression from a string using a custom parsing function.

The parse_expression function is used to parse individual conditions from string slices into expressions.

Returns a Result containing the parsed LogicalExpression if successful, or a ParseError if an error occurred during parsing.

Source§

impl<Condition> LogicalExpression<Condition>

Source

pub fn and(list: Vec<Self>) -> Self

Creates a new logical expression representing the logical AND of the given list of expressions.

If the list contains only one expression, it is returned as is.

Source

pub fn or(list: Vec<Self>) -> Self

Creates a new logical expression representing the logical OR of the given list of expressions.

If the list contains only one expression, it is returned as is.

Source§

impl<Condition: Clone> LogicalExpression<Condition>

Source

pub fn expand(self) -> Vec<Vec<Condition>>

Expands the logical expression into a list of lists, where the inner lists represent the AND conditions and the outer lists represent the OR conditions.

Examples found in repository?
examples/example.rs (line 5)
3fn main() {
4    let expression: LogicalExpression<String> = LogicalExpression::parse("a & (b | c)").unwrap();
5    let expanded = expression.expand();
6    println!("{expanded:?}");
7}

Trait Implementations§

Source§

impl<Condition: Clone> Clone for LogicalExpression<Condition>

Source§

fn clone(&self) -> LogicalExpression<Condition>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Condition: Debug> Debug for LogicalExpression<Condition>

Source§

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

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

impl<Condition: PartialEq> PartialEq for LogicalExpression<Condition>

Source§

fn eq(&self, other: &LogicalExpression<Condition>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Condition: Eq> Eq for LogicalExpression<Condition>

Source§

impl<Condition> StructuralPartialEq for LogicalExpression<Condition>

Auto Trait Implementations§

§

impl<Condition> Freeze for LogicalExpression<Condition>
where Condition: Freeze,

§

impl<Condition> RefUnwindSafe for LogicalExpression<Condition>
where Condition: RefUnwindSafe,

§

impl<Condition> Send for LogicalExpression<Condition>
where Condition: Send,

§

impl<Condition> Sync for LogicalExpression<Condition>
where Condition: Sync,

§

impl<Condition> Unpin for LogicalExpression<Condition>
where Condition: Unpin,

§

impl<Condition> UnwindSafe for LogicalExpression<Condition>
where Condition: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.