1use crate::prelude::*;
2use serde::{Deserialize, Serialize};
3use std::str::FromStr;
4
5#[derive(Serialize, Deserialize)]
6pub struct Repository {
7 repo: RepositoryInner,
8}
9
10#[derive(Serialize, Deserialize)]
11struct RepositoryInner {
12 name: String,
13 edition: String,
14 #[serde(default = "default_albums")]
15 albums: Vec<String>,
16}
17
18fn default_albums() -> Vec<String> {
19 vec!["album".into()]
20}
21
22impl FromStr for Repository {
23 type Err = Error;
24
25 fn from_str(s: &str) -> Result<Self, Self::Err> {
26 let val: Repository = toml::from_str(s).map_err(|e| Error::TomlParseError {
27 target: "Repository",
28 input: s.to_string(),
29 err: e,
30 })?;
31 Ok(val)
32 }
33}
34
35impl ToString for Repository {
36 fn to_string(&self) -> String {
37 toml::to_string_pretty(&self).unwrap()
38 }
39}
40
41impl Repository {
42 pub fn name(&self) -> &str {
43 self.repo.name.as_ref()
44 }
45
46 pub fn edition(&self) -> &str {
47 self.repo.edition.as_ref()
48 }
49
50 pub fn albums(&self) -> &[String] {
51 self.repo.albums.as_ref()
52 }
53}