diff --git a/meilidb-schema/src/lib.rs b/meilidb-schema/src/lib.rs index 0963b68ef..6e974594b 100644 --- a/meilidb-schema/src/lib.rs +++ b/meilidb-schema/src/lib.rs @@ -99,6 +99,12 @@ struct InnerSchema { } impl Schema { + fn to_builder(&self) -> SchemaBuilder { + let identifier = self.inner.identifier.clone(); + let attributes = self.attributes_ordered(); + SchemaBuilder { identifier, attributes } + } + pub fn from_toml(mut reader: R) -> Result> { let mut buffer = Vec::new(); reader.read_to_end(&mut buffer)?; @@ -107,10 +113,7 @@ impl Schema { } pub fn to_toml(&self, mut writer: W) -> Result<(), Box> { - let identifier = self.inner.identifier.clone(); - let attributes = self.attributes_ordered(); - let builder = SchemaBuilder { identifier, attributes }; - + let builder = self.to_builder(); let string = toml::to_string_pretty(&builder)?; writer.write_all(string.as_bytes())?; @@ -125,9 +128,7 @@ impl Schema { } pub fn to_json(&self, mut writer: W) -> Result<(), Box> { - let identifier = self.inner.identifier.clone(); - let attributes = self.attributes_ordered(); - let builder = SchemaBuilder { identifier, attributes }; + let builder = self.to_builder(); let string = serde_json::to_string_pretty(&builder)?; writer.write_all(string.as_bytes())?;