fn html_to_color(html: &str) -> Option<Color32> {
    use std::convert::TryFrom;
    let mut html = html.chars();
    // HTML Color codes require exactly 9 characters (hash + 8 digits).
    // We will also support 6 where we assume that alpha is 255.
    if let Some(char) = html.next() {
        if char != '#' {
            return None;
        }
    }
    let red = if let (Some(red1), Some(red2)) = (html.next(), html.next()) {
        if let (Some(r1), Some(r2)) = (red1.to_digit(16), red2.to_digit(16)) {
            Some(r1 * 16 + r2)
        } else {
            None
        }
    } else {
        None
    };
    let green = if let (Some(green1), Some(green2)) = (html.next(), html.next()) {
        if let (Some(g1), Some(g2)) = (green1.to_digit(16), green2.to_digit(16)) {
            Some(g1 * 16 + g2)
        } else {
            None
        }
    } else {
        None
    };
    let blue = if let (Some(blue1), Some(blue2)) = (html.next(), html.next()) {
        if let (Some(b1), Some(b2)) = (blue1.to_digit(16), blue2.to_digit(16)) {
            Some(b1 * 16 + b2)
        } else {
            None
        }
    } else {
        None
    };
    let alpha = if let (Some(alpha1), Some(alpha2)) = (html.next(), html.next()) {
        if let (Some(a1), Some(a2)) = (alpha1.to_digit(16), alpha2.to_digit(16)) {
            Some(a1 * 16 + a2)
        } else {
            None
        }
    } else {
        Some(255)
    };
    if let (Some(r), Some(b), Some(g), Some(a)) = (red, green, blue, alpha) {
        if let (Ok(r), Ok(b), Ok(g), Ok(a)) = (
            u8::try_from(r),
            u8::try_from(g),
            u8::try_from(b),
            u8::try_from(a),
        ) {
            Some(Color32::from_rgba_premultiplied(r, g, b, a))
        } else {
            None
        }
    } else {
        None
    }
}
// Returns the html color if it is able to or None if it cannot convert it.
Returns the html color if it is able to or None if it cannot convert it.
Returns the html color if it is able to or None if it cannot convert it .
fn html_to_color(html: &str) -> Option<Color32> {
    use std::convert::TryFrom;
    let mut html = html.chars();
    // HTML Color codes require exactly 9 characters (hash + 8 digits).
    // We will also support 6 where we assume that alpha is 255.
    if let Some(char) = html.next() {
        if char != '#' {
            return None;
        }
    }
    let red = if let (Some(red1), Some(red2)) = (html.next(), html.next()) {
        if let (Some(r1), Some(r2)) = (red1.to_digit(16), red2.to_digit(16)) {
            Some(r1 * 16 + r2)
        } else {
            None
        }
    } else {
        None
    };
    let green = if let (Some(green1), Some(green2)) = (html.next(), html.next()) {
        if let (Some(g1), Some(g2)) = (green1.to_digit(16), green2.to_digit(16)) {
            Some(g1 * 16 + g2)
        } else {
            None
        }
    } else {
        None
    };
    let blue = if let (Some(blue1), Some(blue2)) = (html.next(), html.next()) {
        if let (Some(b1), Some(b2)) = (blue1.to_digit(16), blue2.to_digit(16)) {
            Some(b1 * 16 + b2)
        } else {
            None
        }
    } else {
        None
    };
    let alpha = if let (Some(alpha1), Some(alpha2)) = (html.next(), html.next()) {
        if let (Some(a1), Some(a2)) = (alpha1.to_digit(16), alpha2.to_digit(16)) {
            Some(a1 * 16 + a2)
        } else {
            None
        }
    } else {
        Some(255)
    };
    if let (Some(r), Some(b), Some(g), Some(a)) = (red, green, blue, alpha) {
        if let (Ok(r), Ok(b), Ok(g), Ok(a)) = (
            u8::try_from(r),
            u8::try_from(g),
            u8::try_from(b),
            u8::try_from(a),
        ) {
            Some(Color32::from_rgba_premultiplied(r, g, b, a))
        } else {
            None
        }
    } else {
        None
    }
}
fn html_to_color ( html : & str ) -> Option < Color32 > { use std :: convert :: TryFrom ; let mut html = html . chars ( ) ; // HTML Color codes require exactly 9 characters (hash + 8 digits). // We will also support 6 where we assume that alpha is 255. if let Some ( char ) = html . next ( ) { if char != '#' { return None ; } } let red = if let ( Some ( red1 ) , Some ( red2 ) ) = ( html . next ( ) , html . next ( ) ) { if let ( Some ( r1 ) , Some ( r2 ) ) = ( red1 . to_digit ( 16 ) , red2 . to_digit ( 16 ) ) { Some ( r1 * 16 + r2 ) } else { None } } else { None } ; let green = if let ( Some ( green1 ) , Some ( green2 ) ) = ( html . next ( ) , html . next ( ) ) { if let ( Some ( g1 ) , Some ( g2 ) ) = ( green1 . to_digit ( 16 ) , green2 . to_digit ( 16 ) ) { Some ( g1 * 16 + g2 ) } else { None } } else { None } ; let blue = if let ( Some ( blue1 ) , Some ( blue2 ) ) = ( html . next ( ) , html . next ( ) ) { if let ( Some ( b1 ) , Some ( b2 ) ) = ( blue1 . to_digit ( 16 ) , blue2 . to_digit ( 16 ) ) { Some ( b1 * 16 + b2 ) } else { None } } else { None } ; let alpha = if let ( Some ( alpha1 ) , Some ( alpha2 ) ) = ( html . next ( ) , html . next ( ) ) { if let ( Some ( a1 ) , Some ( a2 ) ) = ( alpha1 . to_digit ( 16 ) , alpha2 . to_digit ( 16 ) ) { Some ( a1 * 16 + a2 ) } else { None } } else { Some ( 255 ) } ; if let ( Some ( r ) , Some ( b ) , Some ( g ) , Some ( a ) ) = ( red , green , blue , alpha ) { if let ( Ok ( r ) , Ok ( b ) , Ok ( g ) , Ok ( a ) ) = ( u8 :: try_from ( r ) , u8 :: try_from ( g ) , u8 :: try_from ( b ) , u8 :: try_from ( a ) , ) { Some ( Color32 :: from_rgba_premultiplied ( r , g , b , a ) ) } else { None } } else { None } }
Returns the html color if it is able to or None if it cannot convert it.
Returns the html color if it is able to or None if it cannot convert it .
html
&str