-
I'd like to deserialize a type that implements #[test]
fn wat() {
use serde_with::{Bytes, FromInto};
#[derive(Clone, Debug)]
struct Wrapper([u8; 5]);
impl From<[u8; 5]> for Wrapper {
fn from(bytes: [u8; 5]) -> Self {
Self(bytes)
}
}
#[serde_as]
#[derive(Clone, Debug, Deserialize)]
struct Test {
#[serde_as(as = "FromInto<Bytes>")]
bytes: Wrapper,
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I am unsure what you actually want to achieve. It would help if you could extend your code snippet to a fully runnable example. Using From your snippet it seems what you want to have is this. #[serde_as]
#[derive(Clone, Debug, serde::Deserialize)]
struct Test {
#[serde_as(as = "FromInto<[u8; 5]>")]
bytes: Wrapper,
} |
Beta Was this translation helpful? Give feedback.
I am unsure what you actually want to achieve. It would help if you could extend your code snippet to a fully runnable example. Using
FromInto
like you suggest won't work, sinceBytes
itself cannot be serialized. It does not implementSerialize
orDeserialize
, which is required forFromInto
.From your snippet it seems what you want to have is this.