pub struct Forwardable<T> {
pub inner: T,
/* private fields */
}Expand description
A wrapper that holds domain data along with forward compatibility context.
This type preserves information from unknown versions so that when saved, the data can be written back with minimal information loss.
§Usage
ⓘ
// Load with forward compatibility
let mut task: Forwardable<TaskEntity> = migrator.load_forward("task", json)?;
// Access inner data (Deref makes this transparent)
task.title = "updated".to_string();
// Check if it was a lossy load
if task.was_lossy() {
warn!("Loaded from unknown version: {}", task.original_version());
}
// Save preserving unknown fields and original version
let json = migrator.save_forward(&task)?;Fields§
§inner: TThe inner domain data.
Implementations§
Source§impl<T> Forwardable<T>
impl<T> Forwardable<T>
Sourcepub fn original_version(&self) -> &str
pub fn original_version(&self) -> &str
Returns the original version of the data.
Sourcepub fn unknown_fields(&self) -> &Map<String, Value>
pub fn unknown_fields(&self) -> &Map<String, Value>
Returns the unknown fields that were preserved.
Sourcepub fn context(&self) -> &ForwardContext
pub fn context(&self) -> &ForwardContext
Returns a reference to the forward context.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the wrapper and returns the inner value.
Trait Implementations§
Source§impl<T: Clone> Clone for Forwardable<T>
impl<T: Clone> Clone for Forwardable<T>
Source§fn clone(&self) -> Forwardable<T>
fn clone(&self) -> Forwardable<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for Forwardable<T>
impl<T: Debug> Debug for Forwardable<T>
Source§impl<T> Deref for Forwardable<T>
impl<T> Deref for Forwardable<T>
Source§impl<T> DerefMut for Forwardable<T>
impl<T> DerefMut for Forwardable<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Forwardable<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Forwardable<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for Forwardable<T>where
T: Freeze,
impl<T> RefUnwindSafe for Forwardable<T>where
T: RefUnwindSafe,
impl<T> Send for Forwardable<T>where
T: Send,
impl<T> Sync for Forwardable<T>where
T: Sync,
impl<T> Unpin for Forwardable<T>where
T: Unpin,
impl<T> UnsafeUnpin for Forwardable<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Forwardable<T>where
T: UnwindSafe,
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