appstruct_schema/schema/
snapshot.rs1use super::{DatabaseSchema, SCHEMA_VERSION};
2
3pub fn to_json(schema: &DatabaseSchema) -> Result<String, serde_json::Error> {
9 let mut value = serde_json::to_string_pretty(schema)?;
10 value.push('\n');
11 Ok(value)
12}
13
14pub fn from_json(source: &str) -> Result<DatabaseSchema, serde_json::Error> {
20 let schema: DatabaseSchema = serde_json::from_str(source)?;
21 match schema.schema_version {
22 SCHEMA_VERSION => Ok(schema),
23 found => Err(serde_json::Error::io(std::io::Error::new(
24 std::io::ErrorKind::InvalidData,
25 format!("unsupported schema snapshot version {found}; expected {SCHEMA_VERSION}"),
26 ))),
27 }
28}