Skip to main content

Transformation

Struct Transformation 

Source
pub struct Transformation { /* private fields */ }
Expand description

A builder-style transformation of CBOR or EDN data.

A transformation encodes changes that can be applied to a Transformable such as a StandaloneItem or a Sequence.

While methods on those and the application module provide fine granularity and arbitrary operations, many use cases do not require the finest control – and applying changes manually can lead to suboptimal results if not done in the right sequence.

Note that not all transformations have an effect for all input and output formats (any of CBOR-to-EDN, EDN-to-CBOR, EDN-to-EDN and CBOR-to-CBOR). For example, operations that influence indentation or comments have no practical effect when the transformation’s output is encoded to CBOR, and operations that decode application-oriented literals have no effect when the input is decoded from CBOR.

Implementations§

Source§

impl Transformation

Source

pub const fn new() -> Self

Creates a transformation builder that applies no changes.

Source

pub fn apply_to<'a>(&self, item: &mut impl Transformable<'a>)

Source§

impl Transformation

§Groups of transformations transformations

Source

pub const fn pretty(self) -> Self

Applies any transformation that making the EDN well-readable for humans.

Currently, this applies indentation and processes all known tags to produce corresponding application-oriented literals (or, in case of tags 2 and 3, to EDN numbers).

Source

pub const fn for_cbor_serialization(self) -> Self

Applies the minimal transformations that are necessary for expressing general EDN as CBOR.

Currently, this is an alias for Self::aol_to_item() (and the author lacks the imagination on whether this would ever need other transformations; the one that comes to mind is converting big integers from EDN to CBOR, but that currently happens automatically at serialization time).

Source§

impl Transformation

§Single transformations

Source

pub const fn minify(self) -> Self

Removes all comments and spaces from the EDN.

Source

pub const fn indent(self) -> Self

Applies some default indentation to the EDN.

Output will have a final newline if the general structure is multiline.

Source

pub const fn indent_with_final_newline(self) -> Self

Applies some default indentation to the EDN.

Output will have a final newline unconditionally

Source

pub const fn from_999(self) -> Self

Recognizes Tag 999 and turns it into application-oriented literals.

While this is mostly useful to obtain pretty EDN from an application that, knowing its domain CBOR, prepared tags for pretty-printing, it can also interact with other options that recognize application-oriented literals.

Source

pub const fn to_999(self) -> Self

Produces Tag 999 for all application-oriented literals that are not converted to items in other steps.

This is applied last, after any other transformation option that process application-oriented literals.

Source

pub const fn tag_to_aol(self) -> Self

Recognizes tags to produce application-oriented literals or annotations inside the tag.

Source

pub const fn bignum_tag_to_edn_integer(self) -> Self

Source

pub const fn aol_to_item(self) -> Self

Turns recognized application-oriented literals into their CBOR items.

Source

pub fn annotate_unwrapped_tag(self, tag_number: u64) -> Self

Annotates (by turning into an AOL, adding comments or processing nested items) the top-level structure .

Source

pub fn annotate_cose_header_map(self) -> Self

Source

pub const fn bytestring_heuristics(self) -> Self

Decides 'abc' and h'616263' based on its content

Trait Implementations§

Source§

impl Clone for Transformation

Source§

fn clone(&self) -> Transformation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Transformation

Source§

impl Debug for Transformation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transformation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.