fn hex_to_rgba8<'de, D>(deserializer: D) -> Result<Vec<RGBA8>, D::Error>
where
    D: Deserializer<'de>,
{
    struct ColorVec(PhantomData<Vec<RGBA8>>);

    impl<'de> de::Visitor<'de> for ColorVec {
        type Value = Vec<RGBA8>;

        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
            formatter.write_str("List of Colors as hex values")
        }

        fn visit_seq<S>(self, mut visitor: S) -> Result<Self::Value, S::Error>
        where
            S: de::SeqAccess<'de>,
        {
            let mut out: Vec<RGBA8> = Vec::with_capacity(visitor.size_hint().unwrap_or(0));

            // While there are entries remaining in the input, add them
            // into our vec.
            while let Some(value) = visitor.next_element::<String>()? {
                let value = value.trim_start_matches("#");
                let value = u32::from_str_radix(value, 16)
                    .map_err(|_| serde::de::Error::custom(format!("invalid color [{}]!", value)))?;

                let r = ((value & 0xFF0000) >> 16) as u8;
                let g = ((value & 0x00FF00) >> 8) as u8;
                let b = (value & 0x0000FF) as u8;
                out.push(RGBA8::new(r, g, b, 255));
            }

            Ok(out)
        }
    }

    deserializer.deserialize_any(ColorVec(PhantomData))
}
//Deserializes the colors from Vec<String> to Vec<RGBA8>
//currently assumes all the strings are in the format 0xRRGGBB
//in the future we can enhance that to support more string types
//without breaking the api
Deserializes the colors from Vec to Vec
currently assumes all the strings are in the format 0xRRGGBB
in the future we can enhance that to support more string types
without breaking the api
Deserializes the colors from Vec to Vec currently assumes all the strings are in the format 0xRRGGBB in the future we can enhance that to support more string types without breaking the api
fn hex_to_rgba8<'de, D>(deserializer: D) -> Result<Vec<RGBA8>, D::Error>
where
    D: Deserializer<'de>,
{
    struct ColorVec(PhantomData<Vec<RGBA8>>);
    impl<'de> de::Visitor<'de> for ColorVec {
        type Value = Vec<RGBA8>;
        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
            formatter.write_str("List of Colors as hex values")
        }
        fn visit_seq<S>(self, mut visitor: S) -> Result<Self::Value, S::Error>
        where
            S: de::SeqAccess<'de>,
        {
            let mut out: Vec<RGBA8> = Vec::with_capacity(visitor.size_hint().unwrap_or(0));
            // While there are entries remaining in the input, add them
            // into our vec.
            while let Some(value) = visitor.next_element::<String>()? {
                let value = value.trim_start_matches("#");
                let value = u32::from_str_radix(value, 16)
                    .map_err(|_| serde::de::Error::custom(format!("invalid color [{}]!", value)))?;
                let r = ((value & 0xFF0000) >> 16) as u8;
                let g = ((value & 0x00FF00) >> 8) as u8;
                let b = (value & 0x0000FF) as u8;
                out.push(RGBA8::new(r, g, b, 255));
            }
            Ok(out)
        }
    }
    deserializer.deserialize_any(ColorVec(PhantomData))
}
fn hex_to_rgba8 < ' de , D > ( deserializer : D ) -> Result < Vec < RGBA8 > , D :: Error > where D : Deserializer < ' de > , { struct ColorVec ( PhantomData < Vec < RGBA8 > > ) ; impl < ' de > de :: Visitor < ' de > for ColorVec { type Value = Vec < RGBA8 > ; fn expecting ( & self , formatter : & mut fmt :: Formatter ) -> fmt :: Result { formatter . write_str ( " " ) } fn visit_seq < S > ( self , mut visitor : S ) -> Result < Self :: Value , S :: Error > where S : de :: SeqAccess < ' de > , { let mut out : Vec < RGBA8 > = Vec :: with_capacity ( visitor . size_hint ( ) . unwrap_or ( 0 ) ) ; // While there are entries remaining in the input, add them // into our vec. while let Some ( value ) = visitor . next_element :: < String > ( ) ? { let value = value . trim_start_matches ( " " ) ; let value = u32 :: from_str_radix ( value , 16 ) . map_err ( | _ | serde :: de :: Error :: custom ( format ! ( " " value ) ) ) ? ; let r = ( ( value & 0xFF0000 ) >> 16 ) as u8 ; let g = ( ( value & 0x00FF00 ) >> 8 ) as u8 ; let b = ( value & 0x0000FF ) as u8 ; out . push ( RGBA8 :: new ( r , g , b , 255 ) ) ; } Ok ( out ) } } deserializer . deserialize_any ( ColorVec ( PhantomData ) ) }
Deserializes the colors from Vec<String> to Vec<RGBA8>
currently assumes all the strings are in the format 0xRRGGBB
in the future we can enhance that to support more string types
without breaking the api
Deserializes the colors from Vec<String > to Vec<RGBA8 > currently assumes all the strings are in the format 0xRRGGBB in the future we can enhance that to support more string types without breaking the api
deserializer
D
deserializer
D