Using Bytes
on a &Vec<u8>
field
#460
-
.hg If you have, say, macro-generated code that serializes borrowed values, you can't currently use I did take a shot at implementing this myself, since I figured it'd be pretty simple, but I got stuck at adding a test for it: the test assumes that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In general, the type you write inside the This means you can write: #[serde_as(as = "&Bytes")]
vec: &'a Vec<u8>, This is possible due to the generic serde_with/serde_with/src/ser/impls.rs Line 32 in 9e952e2 |
Beta Was this translation helpful? Give feedback.
In general, the type you write inside the
serde_as
attribute should mirror the field type. The only exceptions are the places where you want to change the behavior, such as forVec<u8> -> Bytes
orBTreeMap<X, Y> -> Vec<(X, Y)>
. This also applies to references&
which should be mirrored too.This means you can write:
This is possible due to the generic
SerializeAs
implementation for&T
:serde_with/serde_with/src/ser/impls.rs
Line 32 in 9e952e2