Skip to main content

NamedRule

Struct NamedRule 

Source
pub struct NamedRule<F: Clone> { /* private fields */ }
Expand description

We can create a rule using this struct and pass it into our list of rules directly, For debugging and tracing, it is helpful to see rules by a meaningful name. or we can make use of the named_rule macro (see [tree-morph-macros]).

This struct and macro is for the short form way of defining named rules. You can change the name of the rule by implementing the Rule trait as well.

use tree_morph::prelude::*;
use tree_morph_macros::named_rule;
use uniplate::Uniplate;

#[derive(Debug, Clone, PartialEq, Eq, Uniplate)]
#[uniplate()]
enum Expr {
  // Snip
}

struct Meta;

#[named_rule("CustomName")]
fn my_rule(_: &mut Commands<Expr, Meta>, expr: &Expr, _: &Meta) -> Option<Expr> {
   /// rule implementation
}

This macro will return a helper function called my_rule which returns the NamedRule for us to use. We can add this to our list of rules with vec![my_rule].

If a name is not specified, the functions name will be it’s identifier.

Implementations§

Source§

impl<F: Clone> NamedRule<F>

Source

pub const fn new(name: &'static str, function: F) -> Self

Create a Rule with a specified name.

Trait Implementations§

Source§

impl<F: Clone + Clone> Clone for NamedRule<F>

Source§

fn clone(&self) -> NamedRule<F>

Returns a duplicate 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<T, M, F> Rule<T, M> for NamedRule<F>
where T: Uniplate, F: Fn(&mut Commands<T, M>, &T, &M) -> Option<T> + Clone,

Source§

fn apply( &self, commands: &mut Commands<T, M>, subtree: &T, meta: &M, ) -> Option<T>

Applies the rule to the given subtree and returns the result if applicable. Read more
Source§

fn name(&self) -> &str

Return the name of the rule, will default to anonymous if not specified.
Source§

fn applicable_to(&self) -> Option<Vec<usize>>

None -> Rule applies to all nodes Some(ids) -> Rule only applies to nodes with these discriminant ids

Auto Trait Implementations§

§

impl<F> Freeze for NamedRule<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for NamedRule<F>
where F: RefUnwindSafe,

§

impl<F> Send for NamedRule<F>
where F: Send,

§

impl<F> Sync for NamedRule<F>
where F: Sync,

§

impl<F> Unpin for NamedRule<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for NamedRule<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for NamedRule<F>
where F: 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.