From ba3ac5ea7bebaa26390b86472abd09101b355665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 16 Sep 2019 14:13:58 +0200 Subject: [PATCH] chore: Create an internal Schema::to_builder method --- meilidb-schema/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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())?;