Search code examples
rusthtml5ever

How do I convert a Tendril<UTF8> to &str or String?


I'm using HTML5ever, and I'm trying to put attributes into a Vec<(String, String>) (although (&str, &str) would work too).

Unfortunately, html5ever's attribute values are in Tendril<UTF8>s, not Strings (or QualNames, &strs, etc.). How can I convert one of these Tendrils into a String?


Solution

  • Use its Deref implementation:

    extern crate tendril;
    
    use tendril::{fmt::UTF8, Tendril};
    
    fn example(t: &Tendril<UTF8>) -> &str {
        t
    }
    
    fn main() {}