[][src]Struct future_rss::RssParser

pub struct RssParser {
    pub node_tag: String,
    pub title_tag: String,
    pub link_tag: String,
    pub author_tag: String,
    pub description_tag: String,
    pub guid_tag: String,
    pub publish_tag: String,
    // some fields omitted
}

Rss Parse Utils

Parse Xml

use future_rss::RssParser;

#[tokio::main]
async fn main()->Result<(),Box<dyn std::error::Error>>{
    let mut parser_default = RssParser::new();
    println!("{:?}",parser_default);
    parser_default.set_xml(String::from(
       r#"<?xml version="1.0" encoding="UTF-8" ?>
        <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
            <item>
                <title>Hey!</title>
                <link>examples.com</link>
                <description>hello.world!</description>
                <author>MeteorCat</author>
                <guid>unique key</guid>
                <pubDate>2020-05-28 15:00:00</pubDate>
            </item>
        </rss>
        "#
    ));
    println!("{:?}",parser_default.parse_vec().await?);
    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");
    let rss = parser.parse_vec().await?;
    println!("{:?}",rss);
    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(())
}

Fields

node_tag: Stringtitle_tag: Stringlink_tag: Stringauthor_tag: Stringdescription_tag: Stringguid_tag: Stringpublish_tag: String

Implementations

impl RssParser[src]

pub fn check_xml(&mut self) -> bool[src]

pub fn new() -> Self[src]

pub async fn from_str(xml: String) -> Result<Self, Box<dyn Error>>[src]

pub async fn from_url<'_, '_>(
    url: &'_ str,
    charset: &'_ str
) -> Result<Self, Box<dyn Error>>
[src]

pub async fn from_file<'_>(filename: &'_ str) -> Result<Self, Box<dyn Error>>[src]

pub async fn parse_vec<'_>(&'_ mut self) -> Result<Vec<RssItem>, Box<dyn Error>>[src]

pub async fn parse_json<'_>(&'_ mut self) -> Result<String, Box<dyn Error>>[src]

pub fn set_xml(&mut self, xml: String)[src]

pub fn get_xml(&self) -> &String[src]

Trait Implementations

impl Debug for RssParser[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.