Update RSS example.
This commit is contained in:
parent
8b450cc724
commit
49969b307a
|
@ -1,9 +0,0 @@
|
||||||
<opml version="2.0">
|
|
||||||
<head>
|
|
||||||
<title>Rust Feeds</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml" />
|
|
||||||
<outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml" />
|
|
||||||
</body>
|
|
||||||
</opml>
|
|
|
@ -1,26 +1,31 @@
|
||||||
use std::{error::Error, fs};
|
|
||||||
|
|
||||||
use opml::OPML;
|
use opml::OPML;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
const SAMPLE: &str = r#"<opml version="2.0">
|
||||||
let xml = fs::read_to_string("examples/opml_samples/rust_feeds.opml")?;
|
<head>
|
||||||
|
<title>Rust Feeds</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<outline text="Rust Blog" xmlUrl="https://blog.rust-lang.org/feed.xml" />
|
||||||
|
<outline text="Inside Rust" xmlUrl="https://blog.rust-lang.org/inside-rust/feed.xml" />
|
||||||
|
</body>
|
||||||
|
</opml>"#;
|
||||||
|
|
||||||
let subscriptions = OPML::from_str(&xml)?;
|
/// Run this example using `cargo run --example rss`.
|
||||||
let head = subscriptions.head.unwrap();
|
///
|
||||||
let title = head.title.unwrap();
|
/// Output:
|
||||||
|
/// Rust Feeds
|
||||||
|
/// ──────────
|
||||||
|
/// Rust Blog https://blog.rust-lang.org/feed.xml
|
||||||
|
/// Inside Rust https://blog.rust-lang.org/inside-rust/feed.xml
|
||||||
|
fn main() {
|
||||||
|
let subscriptions = OPML::from_str(SAMPLE).unwrap();
|
||||||
|
|
||||||
|
if let Some(title) = subscriptions.head.and_then(|head| head.title) {
|
||||||
println!("{}", title);
|
println!("{}", title);
|
||||||
println!(" {}", "─".repeat(title.len()));
|
println!("{}", "-".repeat(title.len()));
|
||||||
|
}
|
||||||
|
|
||||||
for outline in subscriptions.body.outlines {
|
for outline in subscriptions.body.outlines {
|
||||||
println!("{}\t{}", outline.text, outline.xml_url.unwrap());
|
println!("{}\t{}", outline.text, outline.xml_url.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
|
||||||
// Rust Feeds
|
|
||||||
// ──────────
|
|
||||||
// Rust Blog https://blog.rust-lang.org/feed.xml
|
|
||||||
// Inside Rust https://blog.rust-lang.org/inside-rust/feed.xml
|
|
||||||
|
|
Loading…
Reference in New Issue