diff --git a/Cargo.toml b/Cargo.toml index 848bc3b..ea1dbe1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jsondb" -version = "0.1.1" +version = "0.1.0" edition = "2021" authors = ["xenofem "] diff --git a/src/lib.rs b/src/lib.rs index af5e749..f8dd7ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,12 +47,9 @@ pub struct JsonDb { /// other fields of the corresponding schema version; earlier versions /// will be migrated to the current version automatically. pub trait Schema: DeserializeOwned + Serialize { - /// Previous schema that can be migrated into the new schema + const VERSION: u32; type Prev: Schema + Into; - /// Schema version number - const VERSION: u32 = Self::Prev::VERSION + 1; - fn parse(s: &str) -> Result { let Version { version } = serde_json::from_str(s)?; match version.cmp(&Self::VERSION) { @@ -67,25 +64,11 @@ pub trait Schema: DeserializeOwned + Serialize { /// /// Implementing this will automatically implement [`Schema`], with /// version number `0` and `Self` as the previous version. -pub trait SchemaV0: DeserializeOwned + Serialize { - /// Set this to false if your version 0 is a pre-`JsonDb` schema - /// that does not include a version number. - const EXPECT_VERSION_NUMBER: bool = true; -} +pub trait SchemaV0: DeserializeOwned + Serialize {} impl Schema for T { - type Prev = Self; const VERSION: u32 = 0; - - fn parse(s: &str) -> Result { - if Self::EXPECT_VERSION_NUMBER { - let Version { version } = serde_json::from_str(s)?; - if version != 0 { - return Err(Error::UnknownVersion(version)); - } - } - Ok(serde_json::from_str(s)?) - } + type Prev = Self; } #[derive(Deserialize)] @@ -233,6 +216,7 @@ mod tests { last_updated: i64, } impl Schema for V1 { + const VERSION: u32 = 1; type Prev = V0; } impl From for V1 { @@ -264,6 +248,7 @@ mod tests { } } impl Schema for V2 { + const VERSION: u32 = 2; type Prev = V1; } impl From for V2 {