Update RSS example.

This commit is contained in:
Bauke 2022-10-02 21:54:15 +02:00
parent 8b450cc724
commit 49969b307a
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 24 additions and 28 deletions

View File

@ -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>

View File

@ -1,26 +1,31 @@
use std::{error::Error, fs};
use opml::OPML;
fn main() -> Result<(), Box<dyn Error>> {
let xml = fs::read_to_string("examples/opml_samples/rust_feeds.opml")?;
const SAMPLE: &str = r#"<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>"#;
let subscriptions = OPML::from_str(&xml)?;
let head = subscriptions.head.unwrap();
let title = head.title.unwrap();
/// Run this example using `cargo run --example rss`.
///
/// 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!(" {}", "".repeat(title.len()));
println!("{}", "-".repeat(title.len()));
}
for outline in subscriptions.body.outlines {
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