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
Implementations§
source§impl OPML
impl OPML
sourcepub fn new(xml: &str) -> Result<Self, Error>
👎Deprecated since 1.1.0: Use from_str instead
pub fn new(xml: &str) -> Result<Self, Error>
Deprecated, use OPML::from_str
instead.
sourcepub fn from_str(xml: &str) -> Result<Self, Error>
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());
}
}
sourcepub fn from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
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();
sourcepub fn add_feed(&mut self, text: &str, url: &str) -> &mut Self
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);
sourcepub fn to_xml(&self) -> Result<String, Error>
👎Deprecated since 1.1.0: Use to_string instead
pub fn to_xml(&self) -> Result<String, Error>
Deprecated, use OPML::to_string
instead.
sourcepub fn to_string(&self) -> Result<String, Error>
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);
sourcepub fn to_writer<W>(&self, writer: &mut W) -> Result<(), Error>where
W: Write,
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<'de> Deserialize<'de> for OPML
impl<'de> Deserialize<'de> for OPML
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq for OPML
impl Eq for OPML
impl StructuralEq for OPML
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more