Skip to main content

EngineBuilder

Struct EngineBuilder 

Source
pub struct EngineBuilder<T, M, R, C>
where T: Uniplate + Send + Sync, R: Rule<T, M> + Clone, C: RewriteCache<T>,
{ /* private fields */ }
Expand description

A builder type for constructing and configuring Engine instances.

Implementations§

Source§

impl<T, M, R> EngineBuilder<T, M, R, NoCache>
where T: Uniplate + Send + Sync, R: Rule<T, M> + Clone,

Source

pub fn new() -> Self

Creates a new builder instance with the default select_first selector.

Source§

impl<T, M, R, C> EngineBuilder<T, M, R, C>
where T: Uniplate + Send + Sync, R: Rule<T, M> + Clone, C: RewriteCache<T>,

Source

pub fn build(self) -> Engine<T, M, R, C>

Consumes the builder and returns the constructed Engine instance.

Source

pub fn add_rule_group(self, rules: Vec<R>) -> Self

Adds a collection of rules with the same priority.

These rules will have a lower priority than previously added groups.

Source

pub fn add_rule(self, rule: R) -> Self

Adds a single rule in a group by itself.

This is a special case of add_rule_group.

Source

pub fn append_rule_groups(self, groups: Vec<Vec<R>>) -> Self

Adds a collection of rule groups to the existing one.

Rule groups maintain the same order and will be lower priority than existing groups.

Source

pub fn add_before_up(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called before moving $dir in the tree.

Source

pub fn add_after_up(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called after moving $dir one node in the tree.

Source

pub fn add_before_down(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called before moving $dir in the tree.

Source

pub fn add_after_down(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called after moving $dir one node in the tree.

Source

pub fn add_before_right(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called before moving $dir in the tree.

Source

pub fn add_after_right(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called after moving $dir one node in the tree.

Source

pub fn add_before_rule(self, handler: fn(&T, &mut M, &R)) -> Self

Register an event handler to be called before attempting a rule

Source

pub fn add_after_rule(self, handler: fn(&T, &mut M, &R, bool)) -> Self

Register an event handler to be called after attempting a rule The boolean signifies whether the rule is applicable

Source

pub fn add_after_apply(self, handler: fn(&T, &mut M, &R)) -> Self

Register an event handler to be called after applying a rule

Source

pub fn add_on_cache_hit(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called on a cache hit

Source

pub fn add_on_cache_miss(self, handler: fn(&T, &mut M)) -> Self

Register an event handler to be called on a cache miss

Source

pub fn set_selector(self, selector: SelectorFn<T, M, R>) -> Self

Sets the selector function to be used when multiple rules are applicable to the same node.

See the morph method of the Engine type for more information.

Source

pub fn add_cacher<Cache: RewriteCache<T>>( self, cacher: Cache, ) -> EngineBuilder<T, M, R, Cache>

Adds caching support to tree-morph.

Recommended to use [HashMapCache] as it has a concrete implementation

Source

pub fn set_parallel(self, parallel: bool) -> Self

Enables or disables parallel rule checking via Rayon.

When enabled, all rules are tested in parallel using par_iter. Defaults to false.

Source

pub fn set_discriminant_fn( self, discriminant_fn: Option<fn(&T) -> usize>, ) -> Self

Sets the discriminant function used for rule prefiltering.

When Some(f) is provided, f is called on each node to compute a unique usize id, which is used to skip rules that do not apply to that node type. When None, prefiltering is disabled and all rules are tried on every node.

Source

pub fn set_fixedpoint(self, fixedpoint: bool) -> Self

Fixed-point application: after a rule fires, re-apply rules to the transformed node until no more rules match, before continuing traversal.

Source

pub fn add_down_predicate(self, predicate: fn(&T) -> bool) -> Self

Adds a predicate that controls whether the engine descends into a node’s children.

Trait Implementations§

Source§

impl<T, M, R> Default for EngineBuilder<T, M, R, NoCache>
where T: Uniplate + Send + Sync, R: Rule<T, M> + Clone,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, M, R, C> From<EngineBuilder<T, M, R, C>> for Engine<T, M, R, C>
where T: Uniplate + Send + Sync, R: Rule<T, M> + Clone, C: RewriteCache<T>,

Source§

fn from(val: EngineBuilder<T, M, R, C>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T, M, R, C> Freeze for EngineBuilder<T, M, R, C>
where C: Freeze,

§

impl<T, M, R, C> RefUnwindSafe for EngineBuilder<T, M, R, C>

§

impl<T, M, R, C> Send for EngineBuilder<T, M, R, C>
where C: Send, R: Send,

§

impl<T, M, R, C> Sync for EngineBuilder<T, M, R, C>
where C: Sync, R: Sync,

§

impl<T, M, R, C> Unpin for EngineBuilder<T, M, R, C>
where C: Unpin, R: Unpin,

§

impl<T, M, R, C> UnsafeUnpin for EngineBuilder<T, M, R, C>
where C: UnsafeUnpin,

§

impl<T, M, R, C> UnwindSafe for EngineBuilder<T, M, R, C>
where C: UnwindSafe, R: 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> 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, 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.