pub mod children;
pub mod related;
pub mod series;
pub mod tags;
pub mod related_tags;
use serde::Deserialize;
use std::fmt::{self, Display, Formatter};
#[derive(Deserialize, Clone, Debug, Default)]
pub struct Response {
pub categories: Vec<Category>,
}
impl Display for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
for item in self.categories.iter() {
match item.fmt(f) {
Ok(_) => (),
Err(e) => return Err(e),
}
match writeln!(f, "") {
Ok(_) => (),
Err(e) => return Err(e),
}
}
Ok(())
}
}
#[derive(Deserialize, Clone, Debug, Default)]
pub struct Category {
pub id: usize,
pub name: String,
pub parent_id: usize,
pub notes: Option<String>,
}
impl Display for Category {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Category {}: {}", self.id, self.name)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::FredClient;
#[test]
fn category_no_options() {
let mut c = match FredClient::new() {
Ok(c) => c,
Err(msg) => {
println!("{}", msg);
assert_eq!(2, 1);
return
},
};
let resp: Response = match c.category(125) {
Ok(resp) => resp,
Err(msg) => {
println!("{}", msg);
assert_eq!(2, 1);
return
},
};
for s in resp.categories {
println!("ID: {} Name: {} ParentID: {}", s.id, s.name, s.parent_id);
}
}
}