Struct opml::OPML[][src]

pub struct OPML {
    pub version: String,
    pub head: Option<Head>,
    pub body: Body,
}

The top-level OPML element.

Fields

version: String

The version attribute from the element, valid values are 1.0, 1.1 and 2.0.

head: Option<Head>

The Head child element. Contains the metadata of the OPML document.

body: Body

The Body child element. Contains all the Outlines.

Implementations

impl OPML[src]

pub fn new(xml: &str) -> Result<Self, Error>[src]

Parses an OPML document.

Example

use opml::{OPML, Outline};

let xml = r#"<opml version="2.0"><head/><body><outline text="Outline"/></body></opml>"#;
let parsed = OPML::new(xml).unwrap();

let mut expected = OPML::default();
expected.body.outlines.push(Outline {
  text: "Outline".to_string(),
  ..Outline::default()
});

assert_eq!(parsed, expected);

pub fn add_feed(&mut self, text: &str, url: &str) -> &mut Self[src]

Helper function to add an Outline element with text and xml_url attributes to the Body. Useful for creating feed lists quickly. This function also exists on the Outline struct to create grouped lists easily.

Example

use opml::{OPML, Outline};

let mut opml = OPML::default();
opml.add_feed("Feed Name", "https://example.com/");
let added_feed = opml.body.outlines.first().unwrap();

let expected_feed = &Outline {
  text: "Feed Name".to_string(),
  xml_url: Some("https://example.com/".to_string()),
  ..Outline::default()
};

assert_eq!(added_feed, expected_feed);

pub fn to_xml(&self) -> Result<String, Error>[src]

Converts the struct to an XML document.

Example

use opml::OPML;

let opml = OPML::default();
let xml = opml.to_xml().unwrap();

let expected = r#"<opml version="2.0"><head/><body/></opml>"#;
assert_eq!(xml, expected);

Trait Implementations

impl Clone for OPML[src]

impl Debug for OPML[src]

impl Default for OPML[src]

impl<'de> Deserialize<'de> for OPML[src]

impl PartialEq<OPML> for OPML[src]

impl Serialize for OPML[src]

impl StructuralPartialEq for OPML[src]

impl<'__input> XmlRead<'__input> for OPML[src]

impl XmlWrite for OPML[src]

Auto Trait Implementations

impl RefUnwindSafe for OPML

impl Send for OPML

impl Sync for OPML

impl Unpin for OPML

impl UnwindSafe for OPML

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> XmlReadOwned for T where
    T: for<'s> XmlRead<'s>, 
[src]