[go: up one dir, main page]

rss/
lib.rs

1// This file is part of rss.
2//
3// Copyright © 2015-2021 The rust-syndication Developers
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the MIT License and/or Apache 2.0 License.
7
8#![warn(missing_docs)]
9#![doc(html_root_url = "https://docs.rs/rss/")]
10
11//! Library for serializing the RSS web content syndication format.
12//!
13//! # Reading
14//!
15//! A channel can be read from any object that implements the `BufRead` trait.
16//!
17//! ## From a file
18//!
19//! ```rust,no_run
20//! use std::fs::File;
21//! use std::io::BufReader;
22//! use rss::Channel;
23//!
24//! let file = File::open("example.xml").unwrap();
25//! let channel = Channel::read_from(BufReader::new(file)).unwrap();
26//! ```
27//!
28//! ### From a buffer
29//!
30//! **Note**: This example requires [reqwest](https://crates.io/crates/reqwest) crate.
31//!
32//! ```rust,ignore
33//! use std::error::Error;
34//! use rss::Channel;
35//!
36//! async fn example_feed() -> Result<Channel, Box<dyn Error>> {
37//!     let content = reqwest::get("http://example.com/feed.xml")
38//!         .await?
39//!         .bytes()
40//!         .await?;
41//!     let channel = Channel::read_from(&content[..])?;
42//!     Ok(channel)
43//! }
44//! ```
45//!
46//! # Writing
47//!
48//! A channel can be written to any object that implements the `Write` trait or converted to an
49//! XML string using the `ToString` trait.
50//!
51//! ```rust
52//! use rss::Channel;
53//!
54//! let channel = Channel::default();
55//! channel.write_to(::std::io::sink()).unwrap(); // write to the channel to a writer
56//! let string = channel.to_string(); // convert the channel to a string
57//! ```
58//!
59//! # Creation
60//!
61//! Builder methods are provided to assist in the creation of channels.
62//!
63//! **Note**: This requires the `builders` feature, which is enabled by default.
64//!
65//! ```
66//! use rss::ChannelBuilder;
67//!
68//! let channel = ChannelBuilder::default()
69//!     .title("Channel Title")
70//!     .link("http://example.com")
71//!     .description("An RSS feed.")
72//!     .build();
73//! ```
74//!
75//! ## Validation
76//!
77//! Validation methods are provided to validate the contents of a channel against the
78//! RSS specification.
79//!
80//! **Note**: This requires enabling the `validation` feature.
81//!
82//! ```rust,ignore
83//! use rss::Channel;
84//! use rss::validation::Validate;
85//!
86//! let channel = Channel::default();
87//! channel.validate().unwrap();
88//! ```
89
90#[cfg(feature = "builders")]
91#[macro_use]
92extern crate derive_builder;
93
94extern crate quick_xml;
95
96#[cfg(feature = "serde")]
97#[cfg(feature = "validation")]
98extern crate chrono;
99#[cfg(feature = "validation")]
100extern crate mime;
101#[cfg(feature = "serde")]
102#[macro_use]
103extern crate serde;
104#[cfg(feature = "validation")]
105extern crate url;
106
107mod category;
108mod channel;
109mod cloud;
110mod enclosure;
111mod guid;
112mod image;
113mod item;
114mod source;
115mod textinput;
116
117mod error;
118mod toxml;
119mod util;
120
121/// Types and methods for namespaced extensions.
122pub mod extension;
123
124/// Methods for validating RSS feeds.
125#[cfg(feature = "validation")]
126pub mod validation;
127
128pub use crate::category::Category;
129#[cfg(feature = "builders")]
130pub use crate::category::CategoryBuilder;
131pub use crate::channel::Channel;
132#[cfg(feature = "builders")]
133pub use crate::channel::ChannelBuilder;
134pub use crate::cloud::Cloud;
135#[cfg(feature = "builders")]
136pub use crate::cloud::CloudBuilder;
137pub use crate::enclosure::Enclosure;
138#[cfg(feature = "builders")]
139pub use crate::enclosure::EnclosureBuilder;
140pub use crate::guid::Guid;
141#[cfg(feature = "builders")]
142pub use crate::guid::GuidBuilder;
143pub use crate::image::Image;
144#[cfg(feature = "builders")]
145pub use crate::image::ImageBuilder;
146pub use crate::item::Item;
147#[cfg(feature = "builders")]
148pub use crate::item::ItemBuilder;
149pub use crate::source::Source;
150#[cfg(feature = "builders")]
151pub use crate::source::SourceBuilder;
152pub use crate::textinput::TextInput;
153#[cfg(feature = "builders")]
154pub use crate::textinput::TextInputBuilder;
155
156pub use crate::error::Error;