Crate rss [] [src]

Library for serializing the RSS web content syndication format.

Reading

From a BufRead

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

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

let file = File::open("tests/data/rss2sample.xml").unwrap();
let reader = BufReader::new(file);
let channel = Channel::read_from(reader).unwrap();

From a URL

A channel can also be read from a URL.

To enable this functionality you must enable the from_url feature in your Cargo.toml.

[dependencies]
rss = { version = "*", features = ["from_url"] }
use rss::Channel;

let channel = Channel::from_url("https://feedpress.me/usererror.xml").unwrap();

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.

Example

use std::fs::File;
use std::io::{BufReader, sink};
use rss::Channel;

let file = File::open("tests/data/rss2sample.xml").unwrap();
let reader = BufReader::new(file);
let channel = Channel::read_from(reader).unwrap();

// write to the channel to a writer
channel.write_to(sink()).unwrap();

// convert the channel to a string
let string = channel.to_string();

Creation

A channel can be created using the Builder functions.

Example

use rss::{ChannelBuilder, ImageBuilder};

let image = ImageBuilder::default()
    .url("http://jupiterbroadcasting.com/images/LAS-300-Badge.jpg")
    .title("LAS 300 Logo")
    .link("http://www.jupiterbroadcasting.com")
    .finalize();

let channel = ChannelBuilder::default()
    .title("The Linux Action Show! OGG")
    .link("http://www.jupiterbroadcasting.com")
    .description("Ogg Vorbis audio versions of The Linux Action Show!")
    .image(image)
    .finalize();

Validation

Validation can be performed using either a Channel or a builder.

The the following checks are performed during validation:

  • Ensures that integer properties can be parsed from their string representation into integers
  • Ensures that the integer properties are within their valid range according to the RSS 2.0 specification
  • Ensures that URL properties can be parsed
  • Ensures that string properties where only certain values are allowed fall within those valid values

Example

use rss::Channel;

let input = include_str!("tests/data/rss2sample.xml");
let channel = input.parse::<Channel>().unwrap();
channel.validate().unwrap();

Example

use rss::ImageBuilder;

let builder = ImageBuilder::default()
    .url("http://jupiterbroadcasting.com/images/LAS-300-Badge.jpg")
    .title("LAS 300 Logo")
    .link("http://www.jupiterbroadcasting.com")
    .validate()
    .unwrap();

Reexports

pub use extension::Extension;

Modules

extension

Types and functions for namespaced extensions.

Structs

Category

A representation of the <category> element.

CategoryBuilder

A builder used to create a Category.

Channel

A representation of the <channel> element.

ChannelBuilder

A builder used to create a Channel.

Cloud

A representation of the <cloud> element.

CloudBuilder

A builder used to create a Cloud.

Enclosure

A representation of the <enclosure> element.

EnclosureBuilder

A builder used to create an Enclosure.

Guid

A representation of the <guid> element.

GuidBuilder

A builder used to create an Guid.

Image

A representation of the <image> element.

ImageBuilder

A builder used to create an Image.

Item

A representation of the <item> element.

ItemBuilder

A builder used to create an Item.

Source

A representation of the <source> element.

SourceBuilder

A builder used to create a Source.

TextInput

A representation of the <textInput> element.

TextInputBuilder

A builder used to create a TextInput.

Enums

Error

Types of errors that could occur while parsing an RSS feed.