From 3ed7db573438d3620d295813a81237acb91155cb Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 30 Jun 2018 16:50:32 -0700 Subject: refactor changelog entry spec structure --- rust/fatcat-api/src/client.rs | 2 +- rust/fatcat-api/src/lib.rs | 2 +- rust/fatcat-api/src/models.rs | 152 ++++++++++++++++++++++++------------------ 3 files changed, 89 insertions(+), 67 deletions(-) (limited to 'rust/fatcat-api/src') diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index b94d6f42..8c7e4ef3 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -1248,7 +1248,7 @@ impl Api for Client { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; - let body = serde_json::from_str::(&buf)?; + let body = serde_json::from_str::>(&buf)?; Ok(GetEditorChangelogResponse::FoundMergedChanges(body)) } diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index fd0cfe54..f45e113e 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -235,7 +235,7 @@ pub enum GetEditorResponse { #[derive(Debug, PartialEq)] pub enum GetEditorChangelogResponse { /// Found Merged Changes - FoundMergedChanges(models::Changelogentries), + FoundMergedChanges(Vec), /// Not Found NotFound(models::ErrorResponse), /// Generic Error diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 60330392..7ff39789 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -10,68 +10,7 @@ use std::collections::HashMap; use swagger; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Changelogentries(Vec); - -impl ::std::convert::From> for Changelogentries { - fn from(x: Vec) -> Self { - Changelogentries(x) - } -} - -impl ::std::convert::From for Vec { - fn from(x: Changelogentries) -> Self { - x.0 - } -} - -impl ::std::iter::FromIterator for Changelogentries { - fn from_iter>(u: U) -> Self { - Changelogentries(Vec::::from_iter(u)) - } -} - -impl ::std::iter::IntoIterator for Changelogentries { - type Item = ChangelogentriesInner; - type IntoIter = ::std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl<'a> ::std::iter::IntoIterator for &'a Changelogentries { - type Item = &'a ChangelogentriesInner; - type IntoIter = ::std::slice::Iter<'a, ChangelogentriesInner>; - - fn into_iter(self) -> Self::IntoIter { - (&self.0).into_iter() - } -} - -impl<'a> ::std::iter::IntoIterator for &'a mut Changelogentries { - type Item = &'a mut ChangelogentriesInner; - type IntoIter = ::std::slice::IterMut<'a, ChangelogentriesInner>; - - fn into_iter(self) -> Self::IntoIter { - (&mut self.0).into_iter() - } -} - -impl ::std::ops::Deref for Changelogentries { - type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl ::std::ops::DerefMut for Changelogentries { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ChangelogentriesInner { +pub struct ChangelogEntry { #[serde(rename = "index")] pub index: i64, @@ -82,9 +21,9 @@ pub struct ChangelogentriesInner { pub timestamp: chrono::DateTime, } -impl ChangelogentriesInner { - pub fn new(index: i64, editgroup_id: i64, timestamp: chrono::DateTime) -> ChangelogentriesInner { - ChangelogentriesInner { +impl ChangelogEntry { + pub fn new(index: i64, editgroup_id: i64, timestamp: chrono::DateTime) -> ChangelogEntry { + ChangelogEntry { index: index, editgroup_id: editgroup_id, timestamp: timestamp, @@ -335,6 +274,89 @@ impl EntityEdit { } } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct EntityHistory(Vec); + +impl ::std::convert::From> for EntityHistory { + fn from(x: Vec) -> Self { + EntityHistory(x) + } +} + +impl ::std::convert::From for Vec { + fn from(x: EntityHistory) -> Self { + x.0 + } +} + +impl ::std::iter::FromIterator for EntityHistory { + fn from_iter>(u: U) -> Self { + EntityHistory(Vec::::from_iter(u)) + } +} + +impl ::std::iter::IntoIterator for EntityHistory { + type Item = EntityHistoryInner; + type IntoIter = ::std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl<'a> ::std::iter::IntoIterator for &'a EntityHistory { + type Item = &'a EntityHistoryInner; + type IntoIter = ::std::slice::Iter<'a, EntityHistoryInner>; + + fn into_iter(self) -> Self::IntoIter { + (&self.0).into_iter() + } +} + +impl<'a> ::std::iter::IntoIterator for &'a mut EntityHistory { + type Item = &'a mut EntityHistoryInner; + type IntoIter = ::std::slice::IterMut<'a, EntityHistoryInner>; + + fn into_iter(self) -> Self::IntoIter { + (&mut self.0).into_iter() + } +} + +impl ::std::ops::Deref for EntityHistory { + type Target = Vec; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ::std::ops::DerefMut for EntityHistory { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct EntityHistoryInner { + #[serde(rename = "edit")] + pub edit: models::EntityEdit, + + #[serde(rename = "editgroup")] + pub editgroup: models::Editgroup, + + #[serde(rename = "changelog")] + pub changelog: models::ChangelogEntry, +} + +impl EntityHistoryInner { + pub fn new(edit: models::EntityEdit, editgroup: models::Editgroup, changelog: models::ChangelogEntry) -> EntityHistoryInner { + EntityHistoryInner { + edit: edit, + editgroup: editgroup, + changelog: changelog, + } + } +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ErrorResponse { #[serde(rename = "message")] -- cgit v1.2.3