From b7eae012c9e20c2d7d8eabeff2aad88198f2ec9f Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Tue, 28 Jun 2016 16:38:12 +0200 Subject: [PATCH] Add structs holding metadata for the books --- src/book/metadata.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/book/metadata.rs diff --git a/src/book/metadata.rs b/src/book/metadata.rs new file mode 100644 index 00000000..0be79be7 --- /dev/null +++ b/src/book/metadata.rs @@ -0,0 +1,71 @@ +#[derive(Debug, Clone)] +pub struct BookMetadata { + pub title: String, + pub description: String, + + pub language: Language, + + authors: Vec, + translators: Vec, +} + +#[derive(Debug, Clone)] +pub struct Author { + name: String, + email: Option, +} + +#[derive(Debug, Clone)] +pub struct Language { + name: String, + code: String, +} + + +impl BookMetadata { + pub fn new(title: &str) -> Self { + BookMetadata { + title: title.to_owned(), + description: String::new(), + + language: Language::default(), + + authors: Vec::new(), + translators: Vec::new(), + } + } + + pub fn set_description(&mut self, description: &str) -> &mut Self { + self.description = description.to_owned(); + self + } + + pub fn add_author(&mut self, author: Author) -> &mut Self { + self.authors.push(author); + self + } +} + +impl Author { + pub fn new(name: &str) -> Self { + Author { + name: name.to_owned(), + email: None, + } + } + + pub fn with_email(mut self, email: &str) -> Self { + self.email = Some(email.to_owned()); + self + } +} + + +impl Default for Language { + fn default() -> Self { + Language { + name: String::from("English"), + code: String::from("en"), + } + } +}