use facet::Facet;
use facet_xml as xml;
pub const ATOM_NS: &str = "http://www.w3.org/2005/Atom";
pub type Error = facet_xml::DeserializeError<facet_xml::XmlError>;
pub type SerializeError = facet_xml::SerializeError<facet_xml::XmlSerializeError>;
pub fn from_str<'input, T>(input: &'input str) -> Result<T, Error>
where
T: Facet<'input>,
{
facet_xml::from_str_borrowed(input)
}
pub fn from_slice<'input, T>(input: &'input [u8]) -> Result<T, Error>
where
T: Facet<'input>,
{
facet_xml::from_slice_borrowed(input)
}
pub fn to_string<'facet, T>(value: &T) -> Result<String, SerializeError>
where
T: Facet<'facet> + ?Sized,
{
facet_xml::to_string(value)
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(
xml::ns_all = "http://www.w3.org/2005/Atom",
rename = "feed",
skip_all_unless_truthy
)]
pub struct Feed {
#[facet(xml::element)]
pub id: Option<String>,
#[facet(xml::element)]
pub title: Option<TextContent>,
#[facet(xml::element)]
pub updated: Option<String>,
#[facet(xml::elements, rename = "author")]
pub authors: Vec<Person>,
#[facet(xml::elements, rename = "link")]
pub links: Vec<Link>,
#[facet(xml::elements, rename = "category")]
pub categories: Vec<Category>,
#[facet(xml::elements, rename = "contributor")]
pub contributors: Vec<Person>,
#[facet(xml::element)]
pub generator: Option<Generator>,
#[facet(xml::element)]
pub icon: Option<String>,
#[facet(xml::element)]
pub logo: Option<String>,
#[facet(xml::element)]
pub rights: Option<TextContent>,
#[facet(xml::element)]
pub subtitle: Option<TextContent>,
#[facet(xml::elements, rename = "entry")]
pub entries: Vec<Entry>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(
xml::ns_all = "http://www.w3.org/2005/Atom",
rename = "entry",
skip_all_unless_truthy
)]
pub struct Entry {
#[facet(xml::element)]
pub id: Option<String>,
#[facet(xml::element)]
pub title: Option<TextContent>,
#[facet(xml::element)]
pub updated: Option<String>,
#[facet(xml::elements, rename = "author")]
pub authors: Vec<Person>,
#[facet(xml::elements, rename = "link")]
pub links: Vec<Link>,
#[facet(xml::elements, rename = "category")]
pub categories: Vec<Category>,
#[facet(xml::elements, rename = "contributor")]
pub contributors: Vec<Person>,
#[facet(xml::element)]
pub content: Option<Content>,
#[facet(xml::element)]
pub published: Option<String>,
#[facet(xml::element)]
pub rights: Option<TextContent>,
#[facet(xml::element)]
pub summary: Option<TextContent>,
#[facet(xml::element)]
pub source: Option<Source>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(
xml::ns_all = "http://www.w3.org/2005/Atom",
rename = "source",
skip_all_unless_truthy
)]
pub struct Source {
#[facet(xml::element)]
pub id: Option<String>,
#[facet(xml::element)]
pub title: Option<TextContent>,
#[facet(xml::element)]
pub updated: Option<String>,
#[facet(xml::elements, rename = "author")]
pub authors: Vec<Person>,
#[facet(xml::elements, rename = "link")]
pub links: Vec<Link>,
#[facet(xml::elements, rename = "category")]
pub categories: Vec<Category>,
#[facet(xml::elements, rename = "contributor")]
pub contributors: Vec<Person>,
#[facet(xml::element)]
pub generator: Option<Generator>,
#[facet(xml::element)]
pub icon: Option<String>,
#[facet(xml::element)]
pub logo: Option<String>,
#[facet(xml::element)]
pub rights: Option<TextContent>,
#[facet(xml::element)]
pub subtitle: Option<TextContent>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct Person {
#[facet(xml::element)]
pub name: Option<String>,
#[facet(xml::element)]
pub uri: Option<String>,
#[facet(xml::element)]
pub email: Option<String>,
}
#[derive(Facet, Debug, Clone, Copy, Default, PartialEq, Eq)]
#[facet(rename_all = "lowercase")]
#[repr(u8)]
pub enum TextType {
#[default]
Text,
Html,
Xhtml,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct TextContent {
#[facet(xml::attribute, rename = "type")]
pub content_type: Option<TextType>,
#[facet(xml::text)]
pub content: Option<String>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct Link {
#[facet(xml::attribute)]
pub href: Option<String>,
#[facet(xml::attribute)]
pub rel: Option<String>,
#[facet(xml::attribute, rename = "type")]
pub media_type: Option<String>,
#[facet(xml::attribute)]
pub hreflang: Option<String>,
#[facet(xml::attribute)]
pub title: Option<String>,
#[facet(xml::attribute)]
pub length: Option<u64>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct Category {
#[facet(xml::attribute)]
pub term: Option<String>,
#[facet(xml::attribute)]
pub scheme: Option<String>,
#[facet(xml::attribute)]
pub label: Option<String>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct Generator {
#[facet(xml::attribute)]
pub uri: Option<String>,
#[facet(xml::attribute)]
pub version: Option<String>,
#[facet(xml::text)]
pub name: Option<String>,
}
#[derive(Facet, Debug, Clone, Default)]
#[facet(xml::ns_all = "http://www.w3.org/2005/Atom", skip_all_unless_truthy)]
pub struct Content {
#[facet(xml::attribute, rename = "type")]
pub content_type: Option<String>,
#[facet(xml::attribute)]
pub src: Option<String>,
#[facet(xml::text)]
pub body: Option<String>,
}
pub use facet_xml;