Skip to main content

When

Struct When 

Source
pub struct When<H, P> {
    pub inner: H,
    pub pred: P,
}
Expand description

A handler that runs inner only when pred returns true.

Constructed via HandlerExt::when or the sugar HandlerExt::for_kinds.

§Example

use tree_sitter_utils::{handler_fn, HandlerExt, kind_is};

let h = handler_fn(|_: tree_sitter_utils::Input<()>| "hit".to_owned())
    .when(kind_is(&["identifier"]));
let _ = h;

Fields§

§inner: H

The guarded handler.

§pred: P

The predicate gate.

Trait Implementations§

Source§

impl<Ctx, R, H, P> Handler<Ctx, R> for When<H, P>
where H: Handler<Ctx, R>, P: NodePredicate<Ctx>, Ctx: Copy,

Source§

fn handle<'tree>(&self, input: Input<'tree, Ctx>) -> HandlerResult<R>

Attempt to produce an output value for the given input. Read more

Auto Trait Implementations§

§

impl<H, P> Freeze for When<H, P>
where H: Freeze, P: Freeze,

§

impl<H, P> RefUnwindSafe for When<H, P>

§

impl<H, P> Send for When<H, P>
where H: Send, P: Send,

§

impl<H, P> Sync for When<H, P>
where H: Sync, P: Sync,

§

impl<H, P> Unpin for When<H, P>
where H: Unpin, P: Unpin,

§

impl<H, P> UnsafeUnpin for When<H, P>
where H: UnsafeUnpin, P: UnsafeUnpin,

§

impl<H, P> UnwindSafe for When<H, P>
where H: UnwindSafe, P: 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.

Source§

impl<Ctx, R, T> HandlerExt<Ctx, R> for T
where T: Handler<Ctx, R>,

Source§

fn or<H: Handler<Ctx, R>>(self, other: H) -> Or<Self, H>

Try self; if it returns None, try other. Read more
Source§

fn when<P: NodePredicate<Ctx>>(self, pred: P) -> When<Self, P>

Run self only when pred returns true; otherwise return None. Read more
Source§

fn for_kinds(self, kinds: &'static [&'static str]) -> When<Self, KindIs>

Sugar for .when(kind_is(kinds)) - only handle specific node kinds. Read more
Source§

fn map<F, R2>(self, f: F) -> Map<Self, F, R>
where F: Fn(R) -> R2 + Send + Sync,

Apply f to the output value when self succeeds. Read more
Source§

fn map_input<F>(self, f: F) -> MapInput<Self, F>
where F: for<'tree> Fn(Input<'tree, Ctx>) -> Input<'tree, Ctx> + Send + Sync,

Transform the Input before passing it to self. Read more
Source§

fn and_then<F, R2>(self, f: F) -> AndThen<Self, F, R>
where F: Fn(Input<'_, Ctx>, R) -> Option<R2> + Send + Sync,

On success, pass (input, out) to f, which may itself return None. Read more
Source§

fn climb(self, stop_kinds: &'static [&'static str]) -> Climb<Self>

Retry self on each ancestor until it succeeds, stopping at any kind in stop_kinds or at the root. Read more
Source§

fn or_else_climb<O: Handler<Ctx, R>>( self, other: O, stop_kinds: &'static [&'static str], ) -> OrElseClimb<Self, O>

Try self on the original node; on None, try other on each ancestor. Read more
Source§

fn find_ancestor( self, target_kinds: &'static [&'static str], stop_kinds: &'static [&'static str], ) -> FindAncestor<Self>

Walk up to the nearest strict ancestor in target_kinds, then run self on that ancestor node once. Read more
Source§

fn for_children(self) -> ForChildren<Self>

Apply self to every named child, collect all Some(r) into a Vec<R>, and return Some(vec) (never None). Read more
Source§

fn scan_children(self) -> ScanChildren<Self>

Apply self to each named child in order; return the first Some(r), or None if no child matches. Read more
Source§

fn boxed(self) -> BoxedHandler<Ctx, R>
where Self: 'static, Ctx: Copy,

Erase the concrete type into a BoxedHandler for dynamic dispatch. 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, 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.