#unhtml #html #deserializor

unhtml

deserializor from html

2 releases

0.1.1 Dec 2, 2018
0.1.0 Dec 2, 2018

#58 in #html

Download history 13/week @ 2018-12-03

4 downloads per month
Used in 2 crates

MIT license

22KB
336 lines

unhtml

Build status Crate version License: MIT Rust Docs

There are two trait in crate unhtml

  • FromHtml

The only method of FromHtml you should care about is fn from_html(html: &str) -> Result<Self, Error> and this method is implemented for all types implemented FromStr<E, T>

impl<E, T> FromHtml for T
    where E: std::error::Error + Send + Sync + 'static,
          T: FromStr<Err=E> {
    fn from_html(html: &str) -> Result<Self, Error> {
        Ok(T::from_str(html.trim())?)
    }
}

You can implement FromHtml automatically for struct by crate unhtml_derive Crate version

  • VecFromHtml

VecFromHtml is implemented for Vec<T> where T: FromHtml by default

impl<T> VecFromHtml for Vec<T>
    where T: FromHtml {
    type Elem = T;
}

As FromHtml is implemented for u8 by default

use unhtml::scraper::Html;
use unhtml::VecFromHtml;
let html = Html::parse_fragment(r#"



    
    Title


    
"#
); let results = Vec::<u8>::from_attr("#test > a", "href", html.root_element()).unwrap(); assert_eq!(1u8, results[0]); assert_eq!(2u8, results[1]); assert_eq!(3u8, results[2]);

Dependencies

~3.5MB
~67K SLoC