[go: up one dir, main page]

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// This file is part of rss.
//
// Copyright © 2015-2017 The rust-syndication Developers
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the MIT License and/or Apache 2.0 License.

#![warn(missing_docs)]
#![doc(html_root_url = "https://docs.rs/rss/")]

//! 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.
//!
//! ```rust
//! 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.
//!
//! ```toml
//! [dependencies]
//! rss = { version = "*", features = ["from_url"] }
//! ```
//!
//! ```ignore
//! 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
//!
//! ```rust
//! 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();
//! ```
extern crate quick_xml;
extern crate chrono;
extern crate url;
extern crate mime;

#[cfg(feature = "from_url")]
extern crate reqwest;

mod fromxml;
mod toxml;

mod channel;
pub use channel::Channel;
pub use channel::ChannelBuilder;

mod item;
pub use item::Item;
pub use item::ItemBuilder;

mod category;
pub use category::Category;
pub use category::CategoryBuilder;

mod guid;
pub use guid::Guid;
pub use guid::GuidBuilder;

mod enclosure;
pub use enclosure::Enclosure;
pub use enclosure::EnclosureBuilder;

mod source;
pub use source::Source;
pub use source::SourceBuilder;

mod cloud;
pub use cloud::Cloud;
pub use cloud::CloudBuilder;

mod image;
pub use image::Image;
pub use image::ImageBuilder;

mod textinput;
pub use textinput::TextInput;
pub use textinput::TextInputBuilder;

/// Types and functions for namespaced extensions.
pub mod extension;
pub use extension::Extension;

mod error;
pub use error::Error;