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,
impl<S, T, L> Translation<S, T, L>where
L: Lossiness,
Sourcepub fn new(
source: S,
construct_target: Box<dyn FnOnce(S) -> T>,
diff: Diff,
) -> Self
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§impl<S, T> Translation<S, T, Lossless>
impl<S, T> Translation<S, T, Lossless>
Source§impl<S, T> Translation<S, T, Lossy>
impl<S, T> Translation<S, T, Lossy>
Sourcepub const fn is_lossy(&self) -> bool
pub const fn is_lossy(&self) -> bool
Always returns true; signals that calling [translate_lossy] will
drop data.
[translate_lossy]: Translation::<_, _, Lossy>::translate_lossy
Sourcepub fn translate_lossy(self) -> T
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>
impl<S, T> Display for Translation<S, T, Lossless>
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>
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> 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