pub struct BoxedHandler<Ctx, R>(/* private fields */);Expand description
A type-erased handler that owns a Box<dyn Fn(...)>.
Use this only when you need to store handlers in a collection or return them from a function with an erased type. In hot paths, prefer the zero-cost combinator structs.
Constructed via HandlerExt::boxed.
§Example
use tree_sitter_utils::{handler_fn, HandlerExt, BoxedHandler, Input};
let h: BoxedHandler<(), String> =
handler_fn(|_: Input<()>| "hello".to_owned()).boxed();
let _ = h;Implementations§
Source§impl<Ctx, R> BoxedHandler<Ctx, R>
impl<Ctx, R> BoxedHandler<Ctx, R>
Sourcepub fn new<F>(f: F) -> Self
pub fn new<F>(f: F) -> Self
Wrap a boxed closure as a BoxedHandler.
Trait Implementations§
Auto Trait Implementations§
impl<Ctx, R> Freeze for BoxedHandler<Ctx, R>
impl<Ctx, R> !RefUnwindSafe for BoxedHandler<Ctx, R>
impl<Ctx, R> Send for BoxedHandler<Ctx, R>
impl<Ctx, R> Sync for BoxedHandler<Ctx, R>
impl<Ctx, R> Unpin for BoxedHandler<Ctx, R>
impl<Ctx, R> UnsafeUnpin for BoxedHandler<Ctx, R>
impl<Ctx, R> !UnwindSafe for BoxedHandler<Ctx, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Ctx, R, T> HandlerExt<Ctx, R> for Twhere
T: Handler<Ctx, R>,
impl<Ctx, R, T> HandlerExt<Ctx, R> for Twhere
T: Handler<Ctx, R>,
Source§fn when<P: NodePredicate<Ctx>>(self, pred: P) -> When<Self, P>
fn when<P: NodePredicate<Ctx>>(self, pred: P) -> When<Self, P>
Source§fn for_kinds(self, kinds: &'static [&'static str]) -> When<Self, KindIs>
fn for_kinds(self, kinds: &'static [&'static str]) -> When<Self, KindIs>
Sugar for
.when(kind_is(kinds)) - only handle specific node kinds. Read moreSource§fn climb(self, stop_kinds: &'static [&'static str]) -> Climb<Self>
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 moreSource§fn or_else_climb<O: Handler<Ctx, R>>(
self,
other: O,
stop_kinds: &'static [&'static str],
) -> OrElseClimb<Self, O>
fn or_else_climb<O: Handler<Ctx, R>>( self, other: O, stop_kinds: &'static [&'static str], ) -> OrElseClimb<Self, O>
Source§fn find_ancestor(
self,
target_kinds: &'static [&'static str],
stop_kinds: &'static [&'static str],
) -> FindAncestor<Self>
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 moreSource§fn for_children(self) -> ForChildren<Self>
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 moreSource§fn scan_children(self) -> ScanChildren<Self>
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 moreSource§fn boxed(self) -> BoxedHandler<Ctx, R>where
Self: 'static,
Ctx: Copy,
fn boxed(self) -> BoxedHandler<Ctx, R>where
Self: 'static,
Ctx: Copy,
Erase the concrete type into a
BoxedHandler for dynamic dispatch. Read more