Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bluk/readfeed
Pull parsers for various feed formats.
https://github.com/bluk/readfeed
atom atom-feed atom-feed-parser parser rss rss-feed-parser rust xml xml-parser
Last synced: 2 days ago
JSON representation
Pull parsers for various feed formats.
- Host: GitHub
- URL: https://github.com/bluk/readfeed
- Owner: bluk
- License: apache-2.0
- Created: 2023-11-01T16:56:05.000Z (about 1 year ago)
- Default Branch: trunk
- Last Pushed: 2023-12-18T14:11:14.000Z (about 1 year ago)
- Last Synced: 2024-08-09T21:32:20.825Z (5 months ago)
- Topics: atom, atom-feed, atom-feed-parser, parser, rss, rss-feed-parser, rust, xml, xml-parser
- Language: Rust
- Homepage: https://docs.rs/readfeed/
- Size: 50.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# ReadFeed
ReadFeed is a library to process feeds. It provides pull parsers for common feed
formats such as [RSS][rss] and [Atom][atom].* [Latest API Documentation][api_docs]
## Examples
### RSS
```rust
use readfeed::rss::{self, ChannelElem, Elem, ItemElem, RssElem};let input = "
Channel Title
Item Title 1
https://example.com/1
Item Description 1
";
let mut iter = rss::Iter::new(input);
let Some(Elem::Rss(mut rss_iter)) = iter.next() else {
panic!();
};let Some(RssElem::Channel(mut channel_iter)) = rss_iter.next() else {
panic!();
};if let Some(ChannelElem::Title(title)) = channel_iter.next() {
assert_eq!("Channel Title", title.content());
} else {
panic!();
}let Some(ChannelElem::Item(mut item_iter)) = channel_iter.next() else {
panic!();
};if let Some(ItemElem::Title(title)) = item_iter.next() {
assert_eq!("Item Title 1", title.content());
} else {
panic!();
}
if let Some(ItemElem::Link(link)) = item_iter.next() {
assert_eq!("https://example.com/1", link.content());
} else {
panic!();
}
if let Some(ItemElem::Description(desc)) = item_iter.next() {
assert_eq!("Item Description 1", desc.content());
} else {
panic!();
}
assert_eq!(None, item_iter.next());assert_eq!(None, channel_iter.next());
assert_eq!(None, rss_iter.next());
assert_eq!(None, iter.next());
```### Atom
```rust
use readfeed::atom::{self, Elem, EntryElem, FeedElem};let input = r#"
Lorem ipsum dolor sit amet.
2021-02-24T09:08:10Z
urn:uuid:ba9192e8-9e34-4c23-8445-94b67ba316ee
Lorem ipsum dolor sit.
urn:uuid:425ba23c-d283-4580-8a3c-3b67aaa6b373
2021-02-24T09:08:10Z
Lorem ipsum dolor sit amet, consectetur adipiscing.
"#;
let mut iter = atom::Iter::new(input);
let Some(Elem::Feed(mut feed_iter)) = iter.next() else {
panic!();
};if let Some(FeedElem::Title(title)) = feed_iter.next() {
assert_eq!("Lorem ipsum dolor sit amet.", title.content());
} else {
panic!();
}if let Some(FeedElem::Link(link)) = feed_iter.next() {
assert_eq!(Some("https://example.com/"), link.href().map(|v| v.as_str()));
} else {
panic!();
}if let Some(FeedElem::Updated(updated)) = feed_iter.next() {
assert_eq!("2021-02-24T09:08:10Z", updated.content());
} else {
panic!();
}if let Some(FeedElem::Id(id)) = feed_iter.next() {
assert_eq!("urn:uuid:ba9192e8-9e34-4c23-8445-94b67ba316ee", id.content());
} else {
panic!();
}if let Some(FeedElem::Entry(mut entry_iter)) = feed_iter.next() {
if let Some(EntryElem::Title(title)) = entry_iter.next() {
assert_eq!("Lorem ipsum dolor sit.", title.content());
} else {
panic!();
}
if let Some(EntryElem::Link(link)) = entry_iter.next() {
assert_eq!(Some("http://example.com/2021/02/24/hello"), link.href().map(|v| v.as_str()));
} else {
panic!();
}
if let Some(EntryElem::Id(id)) = entry_iter.next() {
assert_eq!("urn:uuid:425ba23c-d283-4580-8a3c-3b67aaa6b373", id.content());
} else {
panic!();
}
if let Some(EntryElem::Updated(updated)) = entry_iter.next() {
assert_eq!("2021-02-24T09:08:10Z", updated.content());
} else {
panic!();
}
if let Some(EntryElem::Summary(summary)) = entry_iter.next() {
assert_eq!("Lorem ipsum dolor sit amet, consectetur adipiscing.", summary.content());
} else {
panic!();
}
assert_eq!(None, entry_iter.next());
} else {
panic!();
}assert_eq!(None, feed_iter.next());
assert_eq!(None, iter.next());
```## Installation
```sh
cargo add readfeed
```By default, the `std` feature is enabled.
### Alloc only
If the host environment has an allocator but does not have access to the Rust
`std` library:```sh
cargo add --no-default-features --features alloc readfeed
```### No allocator / core only
If the host environment does not have an allocator:
```sh
cargo add --no-default-features readfeed
```## License
Licensed under either of [Apache License, Version 2.0][LICENSE_APACHE] or [MIT
License][LICENSE_MIT] at your option.### Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.[LICENSE_APACHE]: LICENSE-APACHE
[LICENSE_MIT]: LICENSE-MIT
[api_docs]: https://docs.rs/readfeed/
[rss]: https://www.rssboard.org/rss-specification
[atom]: https://datatracker.ietf.org/doc/html/rfc4287