3 stable releases

1.0.2 Jun 6, 2020
1.0.1 May 30, 2020
1.0.0 May 28, 2020

#76 in #rss

MIT license

17KB
218 lines

future_rss

Use Rust to Serialize the Rss structure.

Usage

tokio = { version ="*", features = [ "macros","rt-core" ] }
future_rss = "*"

Examples

Parse Xml
use future_rss::*;


#[tokio::main]
async fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::from_url(address,"utf8").await?;
    parser.author_tag = String::from("dc:creator");
    
    let rss = parser.parse_vec().await?;
    println!("{:?}",rss);    
    Ok(())
}

Parse Web XMl

use future_rss::RssParser;

#[tokio::main]
async fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::from_url(address,"utf8").await?;
    parser.author_tag = String::from("dc:creator");
    assert!(parser.parse_json().await.is_ok());
    Ok(())
}

RSS To Json

use future_rss::RssParser;

#[tokio::main]
async fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::from_url(address,"utf8").await?;
    parser.author_tag = String::from("dc:creator");
    assert!(parser.parse_json().await.is_ok());
    Ok(())
}

Rss Request Builder

use future_rss::RssParser;

#[tokio::main]
async fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::new();
    parser.author_tag = "dc:creator".into();
    parser.publish_tag = "pubDate".into();
    let xml = parser.request_xml(address.as_str(),charset.as_str()).await?;
    parser.set_xml(xml);
    assert!(parser.parse_vec().await.is_ok());
    Ok(())
}

Advanced

Examples

Dependencies

~8–12MB
~214K SLoC