#feed #parser

rss

Library for serializing the RSS web content syndication format

44 releases (22 stable)

2.0.9 Aug 27, 2024
2.0.8 May 11, 2024
2.0.7 Jan 13, 2024
2.0.6 Aug 12, 2023
0.0.1 Feb 12, 2015

#125 in Encoding

Download history 7668/week @ 2024-07-18 7981/week @ 2024-07-25 7672/week @ 2024-08-01 8649/week @ 2024-08-08 7702/week @ 2024-08-15 7930/week @ 2024-08-22 8661/week @ 2024-08-29 8651/week @ 2024-09-05 13541/week @ 2024-09-12 19609/week @ 2024-09-19 13230/week @ 2024-09-26 10392/week @ 2024-10-03 9733/week @ 2024-10-10 9533/week @ 2024-10-17 8938/week @ 2024-10-24 7889/week @ 2024-10-31

37,476 downloads per month
Used in 111 crates (90 directly)

MIT/Apache

215KB
3.5K SLoC

rss

Build status Codecov crates.io Status Docs

Library for deserializing and serializing the RSS web content syndication format.

Supported Versions

Reading from the following RSS versions is supported:

  • RSS 0.90
  • RSS 0.91
  • RSS 0.92
  • RSS 1.0
  • RSS 2.0

Writing support is limited to RSS 2.0.

Documentation

Usage

Add the dependency to your Cargo.toml.

[dependencies]
rss = "2.0"

Reading

A channel can be read from any object that implements the BufRead trait.

From a file

use std::fs::File;
use std::io::BufReader;
use rss::Channel;

let file = File::open("example.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();

From a buffer

Note: This example requires reqwest crate.

use std::error::Error;
use rss::Channel;

async fn example_feed() -> Result<Channel, Box<dyn Error>> {
    let content = reqwest::get("http://example.com/feed.xml")
        .await?
        .bytes()
        .await?;
    let channel = Channel::read_from(&content[..])?;
    Ok(channel)
}

Writing

A channel can be written to any object that implements the Write trait or converted to an XML string using the ToString trait.

Note: Writing a channel does not perform any escaping of XML entities.

use rss::Channel;

let channel = Channel::default();
channel.write_to(::std::io::sink()).unwrap(); // // write to the channel to a writer
let string = channel.to_string(); // convert the channel to a string

Creation

Builder methods are provided to assist in the creation of channels.

Note: This requires the builders feature, which is enabled by default.

use rss::ChannelBuilder;

let channel = ChannelBuilder::default()
    .title("Channel Title")
    .link("http://example.com")
    .description("An RSS feed.")
    .build()
    .unwrap();

Validation

Validation methods are provided to validate the contents of a channel against the RSS specification.

Note: This requires enabling the validation feature.

use rss::Channel;
use rss::validation::Validate;

let channel = Channel::default();
channel.validate().unwrap();

Extensions

Elements which have non-default namespaces will be considered extensions. Extensions are stored in Channel.extensions and Item.extensions.

For convenience, Dublin Core, Syndication and iTunes extensions are extracted to structs and stored in as properties on channels and items.

Invalid Feeds

As a best effort to parse invalid feeds rss will default elements declared as "required" by the RSS 2.0 specification to an empty string.

License

Licensed under either of

at your option.

Dependencies

~4–5.5MB
~156K SLoC