RSS Parser
A high-performance, generic RSS parser for Rust that supports streaming parsing from any async input source including files, TCP streams, HTTP responses, and more.
Features
- 🚀 Generic AsyncRead Support: Parse RSS from files, TCP streams, HTTP responses, or any
AsyncReadsource - 🔄 Streaming Interface: Implements
tokio_stream::Streamfor memory-efficient processing of large feeds - 📊 Gradual Parsing: Process RSS items one at a time without loading entire feed into memory
- 🏷️ CDATA Support: Handles both regular text content and CDATA sections
- 🔤 Case Insensitive: Robust parsing of RSS feeds with inconsistent tag casing
- ⚡ Async/Await: Built on tokio for high-performance async I/O
- 🛡️ Type Safe: Leverage Rust's type system with custom RSS item structures
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
= "0.31"
= "0.1"
Usage
Define Your RSS Item Structure
use ;
Parse from File
use RssParser;
async
Parse from HTTP Response
use reqwest;
use RssParser;
async
Parse from TCP Stream
use TcpStream;
use RssParser;
async
Using as a Stream
use StreamExt;
use RssParser;
async
Advanced Usage
Custom Input Sources
The parser accepts any type implementing AsyncRead + Unpin:
use Cursor;
use RssParser;
async
Filtering and Processing
use StreamExt;
let parser = from_file.await?;
let recent_articles: = parser
.filter
.take // Take only first 10 matching articles
.collect
.await;
API Reference
RssParser<T, R>
The main parser struct, generic over:
T: Your RSS item type implementingGradualRssItemR: The input source implementingAsyncRead + Unpin
Methods
new(input: R) -> Result<Self, std::io::Error>: Create parser from any AsyncRead sourcefrom_file(path: &str) -> Result<Self, std::io::Error>: Convenience constructor for filesfrom_tcp(stream: TcpStream) -> Result<Self, std::io::Error>: Convenience constructor for TCP streamsnext(&mut self) -> Option<T>: Parse and return the next RSS item- Implements
Stream<Item = T>for use withtokio-stream
GradualRssItem Trait
Implement this trait for your RSS item structures:
XmlNode
Represents a parsed XML node:
Performance
The parser is designed for high performance and low memory usage:
- Streaming: Processes RSS items one at a time, not loading entire feed into memory
- Zero-copy: Minimizes string allocations where possible
- Async: Non-blocking I/O for handling multiple feeds concurrently
Error Handling
The parser uses Rust's standard error handling patterns:
- Constructor methods return
Result<RssParser<T, R>, std::io::Error> next()returnsOption<T>-Noneindicates end of feed or parse error- Malformed XML is handled gracefully, skipping problematic sections when possible
Requirements
- Rust 1.75+
- tokio runtime
quick-xmlfor XML parsingtokio-streamfor Stream implementation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Running Tests
Running Examples
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.0
- Initial release
- Generic AsyncRead support
- Stream trait implementation
- File and TCP convenience constructors
- CDATA support
- Case-insensitive parsing
Related Projects
- quick-xml - Fast XML parser used internally
- tokio - Async runtime
- feed-rs - Alternative feed parser with more format support
Note: This parser is specifically designed for RSS feeds. For Atom feeds or other syndication formats, consider using a more comprehensive feed parsing library.