Skip to content

Commit

Permalink
Add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed May 9, 2015
1 parent f4119c4 commit 4851f17
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,54 @@
[![rss on Crates.io](https://meritbadge.herokuapp.com/rss)](https://crates.io/crates/rss)

[Documentation](https://frewsxcv.github.io/rust-rss/)

## Examples

### Writing

```rust
use rss::{Channel, Item, Rss};

let item = Item {
title: Some(String::from("Ford hires Elon Musk as CEO")),
pub_date: Some(String::from("01 Apr 2019 07:30:00 GMT")),
description: Some(String::from("In an unprecedented move, Ford hires Elon Musk.")),
..Default::default()
};

let channel = Channel {
title: String::from("TechCrunch"),
link: String::from("http://techcrunch.com"),
description: String::from("The latest technology news and information on startups"),
items: vec![item],
..Default::default()
};

let rss = Rss(channel);

let rss_string = rss.to_string();
```

### Reading

```rust
use rss::Rss;

let rss_str = r#"
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Public weblog for Pinboard</title>
<link>http://techcrunch.com</link>
<description>The latest technology news and information on startups</description>
<item>
<title>Ford hires Elon Musk as CEO</title>
<pubDate>01 Apr 2019 07:30:00 GMT</pubDate>
<description>In an unprecedented move, Ford hires Elon Musk.</description>
</item>
</channel>
</rss>
"#;

let rss = Rss::from_reader(&mut rss_str.as_bytes()).unwrap();
```
12 changes: 12 additions & 0 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ use ::{Category, ElementUtils, ViaXml};

/// [RSS 2.0 Specification § Elements of `<item>`]
/// (http://cyber.law.harvard.edu/rss/rss.html#hrelementsOfLtitemgt)
///
/// # Examples
///
/// ```
/// use rss::Item;
///
/// let item = Item {
/// title: Some(String::from("A blog post title")),
/// description: Some(String::from("This is a description of the blog post")),
/// ..Default::default()
/// };
/// ```
#[derive(Default)]
pub struct Item {
pub title: Option<String>,
Expand Down
51 changes: 51 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,57 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Examples
//!
//! ## Writing
//!
//! ```
//! use rss::{Channel, Item, Rss};
//!
//! let item = Item {
//! title: Some(String::from("Ford hires Elon Musk as CEO")),
//! pub_date: Some(String::from("01 Apr 2019 07:30:00 GMT")),
//! description: Some(String::from("In an unprecedented move, Ford hires Elon Musk.")),
//! ..Default::default()
//! };
//!
//! let channel = Channel {
//! title: String::from("TechCrunch"),
//! link: String::from("http://techcrunch.com"),
//! description: String::from("The latest technology news and information on startups"),
//! items: vec![item],
//! ..Default::default()
//! };
//!
//! let rss = Rss(channel);
//!
//! let rss_string = rss.to_string();
//! ```
//!
//! ## Reading
//!
//! ```
//! use rss::Rss;
//!
//! let rss_str = r#"
//! <?xml version="1.0" encoding="UTF-8"?>
//! <rss version="2.0">
//! <channel>
//! <title>Public weblog for Pinboard</title>
//! <link>http://techcrunch.com</link>
//! <description>The latest technology news and information on startups</description>
//! <item>
//! <title>Ford hires Elon Musk as CEO</title>
//! <pubDate>01 Apr 2019 07:30:00 GMT</pubDate>
//! <description>In an unprecedented move, Ford hires Elon Musk.</description>
//! </item>
//! </channel>
//! </rss>
//! "#;
//!
//! let rss = Rss::from_reader(&mut rss_str.as_bytes()).unwrap();
//! ```

mod category;
mod channel;
mod item;
Expand Down

0 comments on commit 4851f17

Please sign in to comment.