Skip to main content

Transformable

Trait Transformable 

Source
pub trait Transformable<'a>: Transformable<'a> {
    // Required method
    fn set_delimiters(&mut self, policy: DelimiterPolicy);

    // Provided methods
    fn visit_application_literals<F>(&mut self, f: &mut F)
       where F: FnMut(String, String, &mut Item<'a>) -> Result<(), String> + ?Sized { ... }
    fn visit_tag<F>(&mut self, f: &mut F)
       where F: FnMut(u64, &mut Item<'a>) -> Result<(), String> + ?Sized { ... }
}
Expand description

Trait that covers operations that are possible on a StandaloneItem, a Sequence or an Item.

Required Methods§

Source

fn set_delimiters(&mut self, policy: DelimiterPolicy)

Alters how space and comments are placed inside the item.

See the policy values for details.

Provided Methods§

Source

fn visit_application_literals<F>(&mut self, f: &mut F)
where F: FnMut(String, String, &mut Item<'a>) -> Result<(), String> + ?Sized,

For each item in the tree that is a single application literal, call a callback.

This is primarily used to apply custom EDN filtering:

let mut full = Sequence::parse("0 /unmodified/, german'zweiundvierzig'").unwrap();
full.visit_application_literals(&mut |id, value: String, item: &mut cbor_edn::Item| {
    if id == "german" {
        let numeric = match value.as_str() {
            "dreiundzwanzig" => 23,
            "zweiundvierzig" => 42,
            _ => todo!(),
        };
        *item = Item::new_integer_decimal(numeric).into();
    }
    Ok(())
});
assert_eq!(full.serialize(), "0 /unmodified/, 42");
Source

fn visit_tag<F>(&mut self, f: &mut F)
where F: FnMut(u64, &mut Item<'a>) -> Result<(), String> + ?Sized,

For each item in the full tree (including embedded representations) that is tagged, call a callback.

Any error string is placed in a comment next to the item. The function should return Ok(()) on any tags it is not interested in visiting.

This is primarily used to apply custom EDN application; see crate::application::dt_tag_to_aol for an example.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a> Transformable<'a> for Sequence<'a>

Source§

impl<'a> Transformable<'a> for StandaloneItem<'a>