Struct opml::OPML

source ·
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§

source§

impl OPML

source

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

👎Deprecated since 1.1.0: Use from_str instead

Deprecated, use OPML::from_str instead.

source

pub fn from_str(xml: &str) -> Result<Self, Error>

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);
Examples found in repository?
examples/rss.rs (line 21)
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
  let subscriptions = OPML::from_str(SAMPLE).unwrap();

  if let Some(title) = subscriptions.head.and_then(|head| head.title) {
    println!("{}", title);
    println!("{}", "-".repeat(title.len()));
  }

  for outline in subscriptions.body.outlines {
    println!("{}\t{}", outline.text, outline.xml_url.unwrap());
  }
}
source

pub fn from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Parses an OPML document from a reader.

Example
use opml::OPML;

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

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

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);
source

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

👎Deprecated since 1.1.0: Use to_string instead

Deprecated, use OPML::to_string instead.

source

pub fn to_string(&self) -> Result<String, Error>

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);
source

pub fn to_writer<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

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

Example
use opml::OPML;

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

Trait Implementations§

source§

impl Clone for OPML

source§

fn clone(&self) -> OPML

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OPML

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for OPML

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for OPML

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for OPML

source§

fn eq(&self, other: &OPML) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for OPML

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'__input> XmlRead<'__input> for OPML

source§

fn from_reader(reader: &mut XmlReader<'__input>) -> XmlResult<Self>

source§

fn from_str(text: &'a str) -> Result<Self, XmlError>

source§

impl XmlWrite for OPML

source§

fn to_writer<W: Write>(&self, writer: &mut XmlWriter<W>) -> XmlResult<()>

source§

fn to_string(&self) -> Result<String, XmlError>

source§

impl Eq for OPML

source§

impl StructuralEq for OPML

source§

impl StructuralPartialEq for OPML

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

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