Skip to main content

Translation

Struct Translation 

Source
pub struct Translation<Source, Target, Lossiness> { /* private fields */ }
Expand description

A pending translation from Source to Target.

The conversion is deferred: the source value and a constructor closure are held together until the caller explicitly calls [translate] (lossless) or [translate_lossy] (lossy). This lets callers inspect the Diff and decide whether to proceed.

[translate]: Translation::<_, , Lossless>::translate [translate_lossy]: Translation::<, _, Lossy>::translate_lossy

Implementations§

Source§

impl<S, T, L> Translation<S, T, L>
where L: Lossiness,

Source

pub fn new( source: S, construct_target: Box<dyn FnOnce(S) -> T>, diff: Diff, ) -> Self

Build a translation from its constituent parts.

Normally called from within Upgrade::upgrade or Downgrade::downgrade implementations.

Source

pub fn diff(&self) -> &Diff

Returns the structural diff between source and target schemas.

Source§

impl<S, T> Translation<S, T, Lossless>

Source

pub const fn is_lossy(&self) -> bool

Always returns false; present for API symmetry with the Lossy impl.

Source

pub fn translate(self) -> T

Consume the translation and produce the target value.

Source§

impl<S, T> Translation<S, T, Lossy>

Source

pub const fn is_lossy(&self) -> bool

Always returns true; signals that calling [translate_lossy] will drop data.

[translate_lossy]: Translation::<_, _, Lossy>::translate_lossy

Source

pub fn translate_lossy(self) -> T

Consume the translation and produce the target value, accepting data loss.

Trait Implementations§

Source§

impl<S, T> Display for Translation<S, T, Lossless>
where T: Debug, S: Debug,

Source§

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

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

impl<S, T> Display for Translation<S, T, Lossy>
where T: Debug, S: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Source, Target, Lossiness> Freeze for Translation<Source, Target, Lossiness>
where Source: Freeze,

§

impl<Source, Target, Lossiness> !RefUnwindSafe for Translation<Source, Target, Lossiness>

§

impl<Source, Target, Lossiness> !Send for Translation<Source, Target, Lossiness>

§

impl<Source, Target, Lossiness> !Sync for Translation<Source, Target, Lossiness>

§

impl<Source, Target, Lossiness> Unpin for Translation<Source, Target, Lossiness>
where Source: Unpin, Lossiness: Unpin,

§

impl<Source, Target, Lossiness> UnsafeUnpin for Translation<Source, Target, Lossiness>
where Source: UnsafeUnpin,

§

impl<Source, Target, Lossiness> !UnwindSafe for Translation<Source, Target, Lossiness>

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.