Struct opml::OPML[][src]

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

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 Outline elements.

Implementations

👎 Deprecated since 1.1.0:

Use from_str instead

Deprecated, use OPML::from_str instead.

Parses an OPML document.

Example

use opml::{OPML, Outline};

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

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

assert_eq!(document, expected);

Parses an OPML document from a reader.

Example

use opml::OPML;
use std::fs::File;

let mut file = File::open("file.opml").unwrap();
let document = OPML::from_reader(&mut file).unwrap();

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 as Outline::add_feed for grouped lists.

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);
👎 Deprecated since 1.1.0:

Use to_string instead

Deprecated, use OPML::to_string instead.

Converts the struct to an XML document.

Example

use opml::OPML;

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

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

Converts the struct to an XML document and writes it using the writer.

Example

use opml::OPML;
use std::fs::File;

let opml = OPML::default();
let mut file = File::create("file.opml").unwrap();
let xml = opml.to_writer(&mut file).unwrap();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.