Make OPMLs (de)serializable with serde.

This commit is contained in:
Bauke 2020-08-05 19:14:11 +02:00
parent b429da1362
commit af3cdaab6c
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 17 additions and 6 deletions

View File

@ -3,7 +3,7 @@
[package] [package]
name = "opml" name = "opml"
authors = ["Holllo <helllo@holllo.cc>"] authors = ["Holllo <helllo@holllo.cc>"]
version = "0.2.1" version = "0.2.2"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
description = "An OPML parser for Rust." description = "An OPML parser for Rust."
repository = "https://gitlab.com/holllo/opml-rs" repository = "https://gitlab.com/holllo/opml-rs"
@ -15,5 +15,9 @@ keywords = ["xml", "opml"]
path = "source/lib.rs" path = "source/lib.rs"
[dependencies] [dependencies]
regex = "1.3.7" regex = "1.3.9"
strong-xml = "0.6.0" strong-xml = "0.6.0"
[dependencies.serde]
version = "1.0.114"
features = ["derive"]

View File

@ -62,10 +62,11 @@
// TODO: Maybe use a date-time type for all the date-time places? // TODO: Maybe use a date-time type for all the date-time places?
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize};
use strong_xml::{XmlError, XmlRead, XmlWrite}; use strong_xml::{XmlError, XmlRead, XmlWrite};
/// The top-level [OPML](struct.OPML.html) element. /// The top-level [OPML](struct.OPML.html) element.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone)] #[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Serialize, Deserialize)]
#[xml(tag = "opml")] #[xml(tag = "opml")]
pub struct OPML { pub struct OPML {
/// The version attribute from the element, valid values are `1.0`, `1.1` and `2.0`. /// The version attribute from the element, valid values are `1.0`, `1.1` and `2.0`.
@ -196,7 +197,9 @@ impl Default for OPML {
/// The [Head](struct.Head.html) child element of [OPML](struct.OPML.html). /// The [Head](struct.Head.html) child element of [OPML](struct.OPML.html).
/// Contains the metadata of the OPML document. /// Contains the metadata of the OPML document.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default)] #[derive(
XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize,
)]
#[xml(tag = "head")] #[xml(tag = "head")]
pub struct Head { pub struct Head {
/// The title of the document. /// The title of the document.
@ -253,7 +256,9 @@ pub struct Head {
} }
/// The [Body](struct.Body.html) child element of [OPML](struct.OPML.html). Contains all the [Outlines](struct.Outline.html). /// The [Body](struct.Body.html) child element of [OPML](struct.OPML.html). Contains all the [Outlines](struct.Outline.html).
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default)] #[derive(
XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize,
)]
#[xml(tag = "body")] #[xml(tag = "body")]
pub struct Body { pub struct Body {
/// All the top-level [Outline](struct.Outline.html) elements. /// All the top-level [Outline](struct.Outline.html) elements.
@ -262,7 +267,9 @@ pub struct Body {
} }
/// The [Outline](struct.Outline.html) element. /// The [Outline](struct.Outline.html) element.
#[derive(XmlWrite, XmlRead, PartialEq, Debug, Clone, Default)] #[derive(
XmlWrite, XmlRead, PartialEq, Debug, Clone, Default, Serialize, Deserialize,
)]
#[xml(tag = "outline")] #[xml(tag = "outline")]
pub struct Outline { pub struct Outline {
/// Every outline element must have at least a text attribute, which is what is displayed when an outliner opens the OPML document. /// Every outline element must have at least a text attribute, which is what is displayed when an outliner opens the OPML document.