[−][src]Struct future_rss::RssParser
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(()) }
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(()) }
Fields
node_tag: String
title_tag: String
link_tag: String
description_tag: String
guid_tag: String
publish_tag: String
Implementations
impl RssParser
[src]
pub fn check_xml(&mut self) -> bool
[src]
Todo: Optimization
pub async fn request_xml<'_, '_, '_>(
&'_ mut self,
url: &'_ str,
charset: &'_ str
) -> Result<String, Box<dyn Error>>
[src]
&'_ mut self,
url: &'_ str,
charset: &'_ str
) -> Result<String, Box<dyn Error>>
Request Rss by Web
pub async fn request_file<'_, '_>(
&'_ mut self,
filename: &'_ str
) -> Result<String, Box<dyn Error>>
[src]
&'_ mut self,
filename: &'_ str
) -> Result<String, Box<dyn Error>>
Request RSS by File
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]
url: &'_ str,
charset: &'_ str
) -> Result<Self, Box<dyn Error>>
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
Auto Trait Implementations
impl RefUnwindSafe for RssParser
impl Send for RssParser
impl Sync for RssParser
impl Unpin for RssParser
impl UnwindSafe for RssParser
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,