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 easy_rss::RssParser;
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()?);
Ok(())
}
§Parse Web XMl
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::from_url(address,"utf8")?;
parser.author_tag = String::from("dc:creator");
let rss = parser.parse_vec()?;
println!("{:?}",rss);
Ok(())
}
§RSS To Json
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let mut parser = RssParser::from_url(address,"utf8")?;
parser.author_tag = String::from("dc:creator");
assert!(parser.parse_json().is_ok());
Ok(())
}
§Rss Request Builder
use easy_rss::RssParser;
fn main()->Result<(),Box<dyn std::error::Error>> {
let address = "https://www.zhihu.com/rss";
let charset = "utf8";
let mut parser = RssParser::new();
parser.author_tag = "dc:creator".into();
parser.publish_tag = "pubDate".into();
let xml = parser.request_xml(address,charset)?;
parser.set_xml(xml);
assert!(parser.parse_vec().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 fn request_xml(&mut self, url: &str, charset: &str) -> Result<String, Error>
pub fn request_xml(&mut self, url: &str, charset: &str) -> Result<String, Error>
Request Rss by Web
Sourcepub async fn request_file(&mut self, filename: &str) -> Result<String, Error>
pub async fn request_file(&mut self, filename: &str) -> Result<String, Error>
Request RSS by File
pub fn new() -> Self
pub fn from_str(xml: String) -> Result<Self, Error>
pub fn from_url(url: &str, charset: &str) -> Result<Self, Error>
pub async fn from_file(filename: &str) -> Result<Self, Error>
pub fn parse_vec(&mut self) -> Result<Vec<RssItem>, Error>
pub fn parse_json(&mut self) -> Result<String, 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