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,
/* private fields */
}
Expand description
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§
Source§impl RssParser
impl RssParser
Sourcepub async fn request_xml(
&mut self,
url: &str,
charset: &str,
) -> Result<String, Box<dyn Error>>
pub async fn request_xml( &mut self, url: &str, charset: &str, ) -> Result<String, Box<dyn Error>>
Request Rss by Web
Sourcepub async fn request_file(
&mut self,
filename: &str,
) -> Result<String, Box<dyn Error>>
pub async fn request_file( &mut self, filename: &str, ) -> Result<String, Box<dyn Error>>
Request RSS by File
pub fn new() -> Self
pub async fn from_str(xml: String) -> Result<Self, Box<dyn Error>>
pub async fn from_url(url: &str, charset: &str) -> Result<Self, Box<dyn Error>>
pub async fn from_file(filename: &str) -> Result<Self, Box<dyn Error>>
pub async fn parse_vec(&mut self) -> Result<Vec<RssItem>, Box<dyn Error>>
pub async fn parse_json(&mut self) -> Result<String, Box<dyn Error>>
pub fn set_xml(&mut self, xml: String)
pub fn get_xml(&self) -> &String
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RssParser
impl RefUnwindSafe for RssParser
impl Send for RssParser
impl Sync for RssParser
impl Unpin for RssParser
impl UnwindSafe for RssParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more