pub struct DynExt(/* private fields */);Expand description
A type-erased extension node — the opt-in X for runtime-composed extension
sets.
DynExt reconstructs the full Extension + Render surface from the object-safe
DynAstExt shims, so it drops into any node (Statement<DynExt>,
Expr<DynExt>, …) and every render/visit site exactly where NoExt or a
concrete X would go — while the static paths keep their zero-cost layout. The
newtype (rather than a bare Box<dyn DynAstExt>) is what lets the node types’
derived PartialEq/Hash/Clone compose; see the module docs.
Build one with new from any concrete extension node, and recover
the concrete type with downcast_ref:
use squonk_ast::render::{DynExt, Render, RenderCtx};
use squonk_ast::{Span, Spanned};
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct MyNode(u32);
impl Spanned for MyNode {
fn span(&self) -> Span { Span::SYNTHETIC }
}
impl Render for MyNode {
fn render(&self, _ctx: &RenderCtx<'_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "my({})", self.0)
}
}
let ext = DynExt::new(MyNode(7));
assert_eq!(ext.downcast_ref::<MyNode>(), Some(&MyNode(7)));
assert_eq!(ext.clone(), ext);Implementations§
Trait Implementations§
impl Eq for DynExt
Source§impl Render for DynExt
impl Render for DynExt
Source§fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
Return the render for this value.
Source§fn operand_binding_power(&self) -> Option<BindingPower>
fn operand_binding_power(&self) -> Option<BindingPower>
The binding power this node contributes when it appears as an operand, or
None (the default) for a self-delimiting node — an atom, call, or
constructor — that never needs parentheses. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DynExt
impl !Send for DynExt
impl !Sync for DynExt
impl !UnwindSafe for DynExt
impl Freeze for DynExt
impl Unpin for DynExt
impl UnsafeUnpin for DynExt
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynAstExt for T
impl<T> DynAstExt for T
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Erase to
&dyn Any for downcasting a node back to its concrete type.Source§fn dyn_clone(&self) -> Box<dyn DynAstExt>
fn dyn_clone(&self) -> Box<dyn DynAstExt>
Clone into a fresh box — the object-safe stand-in for
Clone (whose
Self-returning signature cannot go through a vtable).Source§fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
Structural equality against another erased node — the object-safe stand-in
for
PartialEq (whose &Self argument cannot go through a vtable). Equal
iff other holds the same concrete type and that type deems the values
equal; differently-typed nodes are never equal.