Skip to content

Commit 7dfc6d2

Browse files
committed
Fix example
1 parent 1dca70c commit 7dfc6d2

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# rust-syndication
22

3-
Library for serializing Atom and RSS web feeds. Wraps around [rust-atom](https://github.com/vtduncan/rust-atom) [rust-rss](https://github.com/frewsxcv/rust-rss).
3+
Library for serializing Atom and RSS web feeds. Wraps around [rust-atom](https://github.com/vtduncan/rust-atom) and [rust-rss](https://github.com/frewsxcv/rust-rss).
44

55
## Usage
66

77
### Reading
88
```rust
9-
use syndication::Feed;
10-
119
let atom_str = r#"
1210
<?xml version="1.0" encoding="utf-8"?>
1311
<feed xmlns="http://www.w3.org/2005/Atom">
@@ -22,7 +20,10 @@ let atom_str = r#"
2220
</feed>
2321
"#;
2422

25-
let Feed::Atom(atom_feed) = atom_str.parse::<Feed>().unwrap();
23+
match atom_str.parse::<Feed>().unwrap() {
24+
Feed::Atom(atom_feed) => println!("Atom feed first entry: {:?}", atom_feed.entries[0].title),
25+
_ => {}
26+
};
2627

2728
let rss_str = r#"
2829
<?xml version="1.0" encoding="UTF-8"?>
@@ -40,7 +41,11 @@ let rss_str = r#"
4041
</rss>
4142
"#;
4243

43-
let Feed::RSS(rss_feed) = rss_str.parse::<Feed>().unwrap();
44+
match rss_str.parse::<Feed>().unwrap() {
45+
Feed::RSS(rss_feed) => println!("RSS feed first entry: {:?}",
46+
rss_feed.items[0].title),
47+
_ => {}
48+
};
4449
```
4550

4651
### Writing

examples/read.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
extern crate syndication;
2+
3+
use syndication::Feed;
4+
5+
fn main() {
6+
let atom_str = r#"
7+
<?xml version="1.0" encoding="utf-8"?>
8+
<feed xmlns="http://www.w3.org/2005/Atom">
9+
<id>urn:uuid:b3420f84-6bdf-4f46-a225-f1b9a14703b6</id>
10+
<title>TechCrunch</title>
11+
<updated>2019-04-01T07:30:00Z</updated>
12+
<entry>
13+
<id>urn:uuid:4ae8550b-2987-49fa-9f8c-54c180c418ac</id>
14+
<title>Ford hires Elon Musk as CEO</title>
15+
<updated>2019-04-01T07:30:00Z</updated>
16+
</entry>
17+
</feed>
18+
"#;
19+
20+
match atom_str.parse::<Feed>().unwrap() {
21+
Feed::Atom(atom_feed) => println!("Atom feed first entry: {:?}", atom_feed.entries[0].title),
22+
_ => {}
23+
};
24+
25+
let rss_str = r#"
26+
<?xml version="1.0" encoding="UTF-8"?>
27+
<rss version="2.0">
28+
<channel>
29+
<title>TechCrunch</title>
30+
<link>http://techcrunch.com</link>
31+
<description>The latest technology news and information on startups</description>
32+
<item>
33+
<title>Ford hires Elon Musk as CEO</title>
34+
<pubDate>01 Apr 2019 07:30:00 GMT</pubDate>
35+
<description>In an unprecedented move, Ford hires Elon Musk.</description>
36+
</item>
37+
</channel>
38+
</rss>
39+
"#;
40+
41+
match rss_str.parse::<Feed>().unwrap() {
42+
Feed::RSS(rss_feed) => println!("RSS feed first entry: {:?}",
43+
rss_feed.items[0].title),
44+
_ => {}
45+
};
46+
}

0 commit comments

Comments
 (0)