Compare commits

..

2 Commits

Author SHA1 Message Date
Enrico Lumetti 32740f3b22 Use serde_bare and update format version 2021-03-18 21:21:48 +01:00
Enrico Lumetti 6a2460c42f Implement basics for document migration 2021-03-18 15:21:18 +01:00
6 changed files with 7 additions and 8 deletions

View File

@ -26,7 +26,6 @@ features = ["v2_56"]
version = "0.13.2" version = "0.13.2"
features = ["v3_22"] features = ["v3_22"]
[patch.crates-io] [patch.crates-io]
druid = { git = "https://github.com/doppioandante/druid", branch = "v0.7.0_stiletto", features = ["im", "svg"] } druid = { git = "https://github.com/doppioandante/druid", branch = "v0.7.0_stiletto", features = ["im", "svg"] }
#druid = { path = "../druid/druid/", features = ["im", "svg"] } #druid = { path = "../druid/druid/", features = ["im", "svg"] }

View File

@ -197,7 +197,7 @@ impl Serialize for Path {
PathEl::MoveTo(pt) => Some(Into::<(f64, f64)>::into(pt)), PathEl::MoveTo(pt) => Some(Into::<(f64, f64)>::into(pt)),
PathEl::LineTo(pt) => Some(Into::<(f64, f64)>::into(pt)), PathEl::LineTo(pt) => Some(Into::<(f64, f64)>::into(pt)),
_ => None, _ => None,
})) }).collect::<Vec<(f64, f64)>>())
} }
} }

View File

@ -32,7 +32,7 @@ pub mod commands {
} }
pub const STILETTO_FORMAT_MAJOR: u16 = 0; pub const STILETTO_FORMAT_MAJOR: u16 = 0;
pub const STILETTO_FORMAT_MINOR: u16 = 1; pub const STILETTO_FORMAT_MINOR: u16 = 2;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct DocumentSnapshot { pub struct DocumentSnapshot {
@ -42,7 +42,7 @@ pub struct DocumentSnapshot {
} }
impl DocumentSnapshot { impl DocumentSnapshot {
pub fn to_writer<W: std::io::Write>(&self, writer: W) -> Result<(), serde_json::Error> { pub fn to_writer<W: std::io::Write>(&self, writer: W) -> Result<(), serde_bare::Error> {
serde_json::to_writer_pretty(writer, &self) serde_bare::to_writer(writer, &self)
} }
} }

View File

@ -274,8 +274,8 @@ impl AppDelegate<StilettoState> for Delegate {
} }
if let Some(file_info) = cmd.get(commands::OPEN_FILE) { if let Some(file_info) = cmd.get(commands::OPEN_FILE) {
if let Ok(f) = File::open(file_info.path()) { if let Ok(f) = File::open(file_info.path()) {
let res_snapshot: Result<DocumentSnapshot, serde_json::Error> = let res_snapshot: Result<DocumentSnapshot, serde_bare::Error> =
serde_json::from_reader(f); serde_bare::from_reader(f);
if let Ok(document_snapshot) = res_snapshot { if let Ok(document_snapshot) = res_snapshot {
data.canvas.set_from_snapshot(document_snapshot); data.canvas.set_from_snapshot(document_snapshot);
data.current_file_path = Some(file_info.path().to_path_buf()); data.current_file_path = Some(file_info.path().to_path_buf());

View File

@ -47,7 +47,7 @@ impl StilettoDocument {
pub fn migrate_to_next(self) -> StilettoDocument { pub fn migrate_to_next(self) -> StilettoDocument {
match self { match self {
StilettoDocument::DocumentSnapshot0_1(_) => self, StilettoDocument::DocumentSnapshot0_1(snapshot) => StilettoDocument::DocumentSnapshot0_2(snapshot) ,
StilettoDocument::DocumentSnapshot0_2(_) => self, StilettoDocument::DocumentSnapshot0_2(_) => self,
} }
} }