mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Fix & test rgb deserialization
This commit is contained in:
parent
758687a63e
commit
b7c34f8bdb
1 changed files with 19 additions and 1 deletions
|
@ -461,6 +461,13 @@ pub(crate) mod serde_rgb {
|
||||||
{
|
{
|
||||||
Ok(from_u32(v))
|
Ok(from_u32(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: serde::de::Error,
|
||||||
|
{
|
||||||
|
self.visit_u32(v.try_into().map_err(|_| E::custom("rgb value doesn't fit u32"))?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
d.deserialize_u32(V)
|
d.deserialize_u32(V)
|
||||||
}
|
}
|
||||||
|
@ -481,5 +488,16 @@ pub(crate) mod serde_rgb {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn json() {}
|
fn json() {
|
||||||
|
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
struct Struct {
|
||||||
|
#[serde(with = "self")]
|
||||||
|
color: [u8; 3],
|
||||||
|
}
|
||||||
|
|
||||||
|
let json = format!("{}", 0x00AABBCC);
|
||||||
|
let Struct { color } = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(color, [0xAA, 0xBB, 0xCC])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue