Struct atom_syndication::Feed
source · pub struct Feed {Show 17 fields
pub title: Text,
pub id: String,
pub updated: FixedDateTime,
pub authors: Vec<Person>,
pub categories: Vec<Category>,
pub contributors: Vec<Person>,
pub generator: Option<Generator>,
pub icon: Option<String>,
pub links: Vec<Link>,
pub logo: Option<String>,
pub rights: Option<Text>,
pub subtitle: Option<Text>,
pub entries: Vec<Entry>,
pub extensions: ExtensionMap,
pub namespaces: BTreeMap<String, String>,
pub base: Option<String>,
pub lang: Option<String>,
}
Expand description
Represents an Atom feed
Fields§
§title: Text
A human-readable title for the feed.
id: String
A universally unique and permanent URI.
updated: FixedDateTime
The last time the feed was modified in a significant way.
The authors of the feed.
categories: Vec<Category>
The categories that the feed belongs to.
contributors: Vec<Person>
The contributors to the feed.
generator: Option<Generator>
The software used to generate the feed.
icon: Option<String>
A small image which provides visual identification for the feed.
links: Vec<Link>
The Web pages related to the feed.
logo: Option<String>
A larger image which provides visual identification for the feed.
rights: Option<Text>
Information about rights held in and over the feed.
subtitle: Option<Text>
A human-readable description or subtitle for the feed.
entries: Vec<Entry>
The entries contained in the feed.
extensions: ExtensionMap
The extensions for the feed.
namespaces: BTreeMap<String, String>
The namespaces present in the feed tag.
base: Option<String>
Base URL for resolving any relative references found in the element.
lang: Option<String>
Indicates the natural language for the element.
Implementations§
source§impl Feed
impl Feed
sourcepub fn read_from<B: BufRead>(reader: B) -> Result<Feed, Error>
pub fn read_from<B: BufRead>(reader: B) -> Result<Feed, Error>
Attempt to read an Atom feed from the reader.
§Examples
use std::io::BufReader;
use std::fs::File;
use atom_syndication::Feed;
let file = File::open("example.xml").unwrap();
let feed = Feed::read_from(BufReader::new(file)).unwrap();
sourcepub fn write_to<W: Write>(&self, writer: W) -> Result<W, Error>
pub fn write_to<W: Write>(&self, writer: W) -> Result<W, Error>
Attempt to write this Atom feed to a writer using default WriteConfig
.
§Examples
use std::io::BufReader;
use std::fs::File;
use atom_syndication::Feed;
let feed = Feed {
title: "Feed Title".into(),
id: "Feed ID".into(),
..Default::default()
};
let out = feed.write_to(Vec::new())?;
assert_eq!(&out, br#"<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Feed Title</title><id>Feed ID</id><updated>1970-01-01T00:00:00+00:00</updated></feed>"#);
sourcepub fn write_with_config<W: Write>(
&self,
writer: W,
write_config: WriteConfig
) -> Result<W, Error>
pub fn write_with_config<W: Write>( &self, writer: W, write_config: WriteConfig ) -> Result<W, Error>
Attempt to write this Atom feed to a writer.
§Examples
use std::io::BufReader;
use std::fs::File;
use atom_syndication::{Feed, WriteConfig};
let feed = Feed {
title: "Feed Title".into(),
id: "Feed ID".into(),
..Default::default()
};
let mut out = Vec::new();
let config = WriteConfig {
write_document_declaration: false,
indent_size: Some(2),
};
feed.write_with_config(&mut out, config)?;
assert_eq!(&out, br#"<feed xmlns="http://www.w3.org/2005/Atom">
<title>Feed Title</title>
<id>Feed ID</id>
<updated>1970-01-01T00:00:00+00:00</updated>
</feed>"#);
sourcepub fn title(&self) -> &Text
pub fn title(&self) -> &Text
Return the title of this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_title("Feed Title");
assert_eq!(feed.title(), "Feed Title");
sourcepub fn set_title<V>(&mut self, title: V)
pub fn set_title<V>(&mut self, title: V)
Set the title of this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_title("Feed Title");
sourcepub fn id(&self) -> &str
pub fn id(&self) -> &str
Return the unique URI of this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6");
assert_eq!(feed.id(), "urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6");
sourcepub fn set_id<V>(&mut self, id: V)
pub fn set_id<V>(&mut self, id: V)
Set the unique URI of this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6");
sourcepub fn updated(&self) -> &FixedDateTime
pub fn updated(&self) -> &FixedDateTime
Return the last time that this feed was modified.
§Examples
use atom_syndication::Feed;
use atom_syndication::FixedDateTime;
use std::str::FromStr;
let mut feed = Feed::default();
feed.set_updated(FixedDateTime::from_str("2017-06-03T15:15:44-05:00").unwrap());
assert_eq!(feed.updated().to_rfc3339(), "2017-06-03T15:15:44-05:00");
sourcepub fn set_updated<V>(&mut self, updated: V)where
V: Into<FixedDateTime>,
pub fn set_updated<V>(&mut self, updated: V)where
V: Into<FixedDateTime>,
Set the last time that this feed was modified.
§Examples
use atom_syndication::Feed;
use atom_syndication::FixedDateTime;
use std::str::FromStr;
let mut feed = Feed::default();
feed.set_updated(FixedDateTime::from_str("2017-06-03T15:15:44-05:00").unwrap());
Return the authors of this feed.
§Examples
use atom_syndication::{Feed, Person};
let mut feed = Feed::default();
feed.set_authors(vec![Person::default()]);
assert_eq!(feed.authors().len(), 1);
Set the authors of this feed.
§Examples
use atom_syndication::{Feed, Person};
let mut feed = Feed::default();
feed.set_authors(vec![Person::default()]);
sourcepub fn categories(&self) -> &[Category]
pub fn categories(&self) -> &[Category]
Return the categories this feed belongs to.
§Examples
use atom_syndication::{Feed, Category};
let mut feed = Feed::default();
feed.set_categories(vec![Category::default()]);
assert_eq!(feed.categories().len(), 1);
sourcepub fn set_categories<V>(&mut self, categories: V)
pub fn set_categories<V>(&mut self, categories: V)
Set the categories this feed belongs to.
§Examples
use atom_syndication::{Feed, Category};
let mut feed = Feed::default();
feed.set_categories(vec![Category::default()]);
sourcepub fn contributors(&self) -> &[Person]
pub fn contributors(&self) -> &[Person]
Return the contributors to this feed.
§Examples
use atom_syndication::{Feed, Person};
let mut feed = Feed::default();
feed.set_contributors(vec![Person::default()]);
assert_eq!(feed.contributors().len(), 1);
sourcepub fn set_contributors<V>(&mut self, contributors: V)
pub fn set_contributors<V>(&mut self, contributors: V)
Set the contributors to this feed.
§Examples
use atom_syndication::{Feed, Person};
let mut feed = Feed::default();
feed.set_contributors(vec![Person::default()]);
sourcepub fn generator(&self) -> Option<&Generator>
pub fn generator(&self) -> Option<&Generator>
Return the name of the software used to generate this feed.
§Examples
use atom_syndication::{Feed, Generator};
let mut feed = Feed::default();
feed.set_generator(Generator::default());
assert!(feed.generator().is_some());
sourcepub fn set_generator<V>(&mut self, generator: V)
pub fn set_generator<V>(&mut self, generator: V)
Set the name of the software used to generate this feed.
§Examples
use atom_syndication::{Feed, Generator};
let mut feed = Feed::default();
feed.set_generator(Generator::default());
sourcepub fn icon(&self) -> Option<&str>
pub fn icon(&self) -> Option<&str>
Return the icon for this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_icon("http://example.com/icon.png".to_string());
assert_eq!(feed.icon(), Some("http://example.com/icon.png"));
sourcepub fn set_icon<V>(&mut self, icon: V)
pub fn set_icon<V>(&mut self, icon: V)
Set the icon for this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_icon("http://example.com/icon.png".to_string());
sourcepub fn links(&self) -> &[Link]
pub fn links(&self) -> &[Link]
Return the Web pages related to this feed.
§Examples
use atom_syndication::{Feed, Link};
let mut feed = Feed::default();
feed.set_links(vec![Link::default()]);
assert_eq!(feed.links().len(), 1);
sourcepub fn set_links<V>(&mut self, links: V)
pub fn set_links<V>(&mut self, links: V)
Set the Web pages related to this feed.
§Examples
use atom_syndication::{Feed, Link};
let mut feed = Feed::default();
feed.set_links(vec![Link::default()]);
sourcepub fn logo(&self) -> Option<&str>
pub fn logo(&self) -> Option<&str>
Return the logo for this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_logo("http://example.com/logo.png".to_string());
assert_eq!(feed.logo(), Some("http://example.com/logo.png"));
sourcepub fn set_logo<V>(&mut self, logo: V)
pub fn set_logo<V>(&mut self, logo: V)
Set the logo for this feed.
§Examples
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_logo("http://example.com/logo.png".to_string());
sourcepub fn rights(&self) -> Option<&Text>
pub fn rights(&self) -> Option<&Text>
Return the information about the rights held in and over this feed.
§Examples
use atom_syndication::{Feed, Text};
let mut feed = Feed::default();
feed.set_rights(Text::from("© 2017 John Doe"));
assert_eq!(feed.rights().map(Text::as_str), Some("© 2017 John Doe"));
sourcepub fn set_rights<V>(&mut self, rights: V)
pub fn set_rights<V>(&mut self, rights: V)
Set the information about the rights held in and over this feed.
§Examples
use atom_syndication::{Feed, Text};
let mut feed = Feed::default();
feed.set_rights(Text::from("© 2017 John Doe"));
sourcepub fn subtitle(&self) -> Option<&Text>
pub fn subtitle(&self) -> Option<&Text>
Return the description or subtitle of this feed.
§Examples
use atom_syndication::{Feed, Text};
let mut feed = Feed::default();
feed.set_subtitle(Text::from("Feed subtitle"));
assert_eq!(feed.subtitle().map(Text::as_str), Some("Feed subtitle"));
sourcepub fn set_subtitle<V>(&mut self, subtitle: V)
pub fn set_subtitle<V>(&mut self, subtitle: V)
Set the description or subtitle of this feed.
§Examples
use atom_syndication::{Feed, Text};
let mut feed = Feed::default();
feed.set_subtitle(Text::from("Feed subtitle"));
sourcepub fn entries(&self) -> &[Entry]
pub fn entries(&self) -> &[Entry]
Return the entries in this feed.
§Examples
use atom_syndication::{Feed, Entry};
let mut feed = Feed::default();
feed.set_entries(vec![Entry::default()]);
assert_eq!(feed.entries().len(), 1);
sourcepub fn set_entries<V>(&mut self, entries: V)
pub fn set_entries<V>(&mut self, entries: V)
Set the entries in this feed.
§Examples
use atom_syndication::{Feed, Entry};
let mut feed = Feed::default();
feed.set_entries(vec![Entry::default()]);
sourcepub fn extensions(&self) -> &ExtensionMap
pub fn extensions(&self) -> &ExtensionMap
Return the extensions for this feed.
§Examples
use std::collections::BTreeMap;
use atom_syndication::Feed;
use atom_syndication::extension::{ExtensionMap, Extension};
let extension = Extension::default();
let mut item_map = BTreeMap::<String, Vec<Extension>>::new();
item_map.insert("ext:name".to_string(), vec![extension]);
let mut extension_map = ExtensionMap::default();
extension_map.insert("ext".to_string(), item_map);
let mut feed = Feed::default();
feed.set_extensions(extension_map);
assert_eq!(feed.extensions()
.get("ext")
.and_then(|m| m.get("ext:name"))
.map(|v| v.len()),
Some(1));
sourcepub fn set_extensions<V>(&mut self, extensions: V)where
V: Into<ExtensionMap>,
pub fn set_extensions<V>(&mut self, extensions: V)where
V: Into<ExtensionMap>,
Set the extensions for this feed.
§Examples
use atom_syndication::Feed;
use atom_syndication::extension::ExtensionMap;
let mut feed = Feed::default();
feed.set_extensions(ExtensionMap::default());
sourcepub fn namespaces(&self) -> &BTreeMap<String, String>
pub fn namespaces(&self) -> &BTreeMap<String, String>
Return the namespaces for this feed.
§Examples
use std::collections::BTreeMap;
use atom_syndication::Feed;
let mut namespaces = BTreeMap::new();
namespaces.insert("ext".to_string(), "http://example.com".to_string());
let mut feed = Feed::default();
feed.set_namespaces(namespaces);
assert_eq!(feed.namespaces().get("ext").map(|s| s.as_str()), Some("http://example.com"));
sourcepub fn set_namespaces<V>(&mut self, namespaces: V)
pub fn set_namespaces<V>(&mut self, namespaces: V)
Set the namespaces for this feed.
§Examples
use std::collections::BTreeMap;
use atom_syndication::Feed;
let mut feed = Feed::default();
feed.set_namespaces(BTreeMap::new());