Struct structsy::PrepareOpen
source · pub struct PrepareOpen { /* private fields */ }
Expand description
Prepare open of a structsy file, with migrations possibilities
Implementations§
source§impl PrepareOpen
impl PrepareOpen
sourcepub fn migrate<S, D>(&self) -> SRes<()>where
S: Persistent,
D: Persistent + From<S>,
pub fn migrate<S, D>(&self) -> SRes<()>where S: Persistent, D: Persistent + From<S>,
Migrate an existing persistent struct to a new struct.
In structsy the name and order of the fields matter for the persistence, so each change need to migrate existing data from existing struct layout to the new struct.
Example
use structsy::Structsy;
use structsy_derive::Persistent;
#[derive(Persistent)]
struct PersonV0 {
name:String,
}
#[derive(Persistent)]
struct PersonV1 {
name:String,
surname:String,
}
impl From<PersonV0> for PersonV1 {
fn from(f: PersonV0) -> Self {
PersonV1 {
name: f.name,
surname: "Doe".to_string(),
}
}
}
let prepare = Structsy::prepare_open("path/to/file.stry")?;
prepare.migrate::<PersonV0,PersonV1>()?;
let stry = prepare.open()?;
stry.define::<PersonV1>()?;
Auto Trait Implementations§
impl !RefUnwindSafe for PrepareOpen
impl Send for PrepareOpen
impl Sync for PrepareOpen
impl Unpin for PrepareOpen
impl !UnwindSafe for PrepareOpen
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