pub enum RoleExpr {
    And(Box<RoleExpr>, Box<RoleExpr>),
    Or(Box<RoleExpr>, Box<RoleExpr>),
    Not(Box<RoleExpr>),
    Role(String),
    Invalid,
}
Expand description

A RoleExpr is a boolean expression tree.

It is typically parsed by the RoleExprParser. However it can also be build programmatically.

Here an example for the expression admin or power_user:

use toql_core::role_expr::RoleExpr;

let e = RoleExpr::Role("admin".to_string())
               .or(RoleExpr::Role("power_user".to_string()));
assert_eq!("(`admin`); (`power_user`)", e.to_string());

Notice that the string representation of OR always comes with parenthesis to express logical priority. To validate a role expression use the RoleValidator.

RoleExpr are used by Toql derive generated code.

End users should restrict actions with role expressions through the Toql derive.

Example

Restricting the field’s selection to the roles ‘admin’ or ‘power_user’

use toql_derive::Toql;

#[derive(Toql)]
struct FooBar {
  #[toql(key)]
  id: u64,

  #[toql(roles(load="admin;power_user"))]
  name: Option<String>
}

Variants

And(Box<RoleExpr>, Box<RoleExpr>)

Concatenate both nodes with AND

Or(Box<RoleExpr>, Box<RoleExpr>)

Concatenate both nodes with OR

Not(Box<RoleExpr>)

Negate node

Role(String)

This node is a role name

Invalid

This node is always invalid

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts the given value to a String. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more