pub struct Context {
pub mappers: HashMap<TypeId, Box<Mapper>>,
}Expand description
Context for custom value transformations.
A context holds a collection of mappers keyed by the TypeId of the
input type. When displaying a tree, the context is used to apply
transformations to values before they are rendered.
§Example
use tree_display::Context;
let context = Context::new()
.map(|s: &String| format!("'{}'", s))
.map(|n: &i32| format!("{}", n * 2));Fields§
§mappers: HashMap<TypeId, Box<Mapper>>Map from TypeId to a mapper function for that type.
Implementations§
Source§impl Context
impl Context
Sourcepub fn map<T: 'static, R: Content + 'static>(
self,
f: impl Fn(&T) -> R + 'static,
) -> Self
pub fn map<T: 'static, R: Content + 'static>( self, f: impl Fn(&T) -> R + 'static, ) -> Self
Registers a mapper for a specific type.
The mapper function takes a reference to a value and returns another
value that implements Content. The transformed value will
be used when displaying values of type T in the tree.
To apply a mapper to a specific field in a struct or enum, use the
#[tree(map)] attribute on that field when deriving TreeDisplay.
§Type Parameters
T: The input type to map fromR: The output type that implementsContent
§Example
use tree_display::context::Context;
let context = Context::new()
.map(|s: &String| format!("'{}'", s))
.map(|n: &i32| format!("{}", n * 2));Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl !UnwindSafe for Context
impl Freeze for Context
impl Unpin for Context
impl UnsafeUnpin for Context
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, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
Invokes
WrappingSpan::make_wrapped to wrap an AST node in a span.