-
-
Notifications
You must be signed in to change notification settings - Fork 6
Attribute macro to generate de/serialization functions for fields of big array type #17
Comments
@dtolnay that would indeed be a bit more convenient. Overall I think that I personally don't want to spend too much time on the issue, given that hopefully this will get fixed by the language. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I figured this would be a great way to dig into proc macros, so I played around with it a bit. Who'd guess I'd have a PoC so soon: https://github.com/uint/serbia For now, it only works on structs (tuple or regular). I guess I'm on it! |
serde_with has also recently gained big array support: jonasbb/serde_with#272 Their MSRV is 1.51. Support is a bit more comprehensive than serde-big-array. I need to investigate if there is a reason to keep serde-big-array around or whether I should deprecate it in favour of serde_with. |
So I've been looking at implementing this thing: pub const BUFSIZE: usize = 1024;
pub type Buffer = [u8; BUFSIZE];
#[make_big_arrays_work]
#[derive(Serialize, Deserialize)]
struct S {
#[big_array(BUFSIZE)]
buffer: Buffer,
} I can parse |
Like all of the standard library's traits, Serde's traits are limited to fixed size arrays up to an arbitrary maximum size. Serde defines Serialize and Deserialize impls for arrays up to size 32.
The current workaround for larger arrays in
serde_big_array
is workable but not ideal:It would be nicer to have an attribute macro that makes big arrays work by finding all fields of array type and inserting the appropriate
serde(serialize_with = "...", deserialize_with = "...")
functions (also generated by the attribute macro).The serialize_with attribute should only be emitted if there is a Serialize derive on the data structure, and deserialize_with should only be emitted if there is a Deserialize derive.
Neither attribute should be emitted for a field with array type with literal size that we can see is 32 or smaller.
Attributes do need to be emitted for all arrays of const size not visible to the macro, for example
arr_unknown: [u8; BUFFER_SIZE]
.Optionally, also support type aliased arrays by specifying the array size in an attribute.
The text was updated successfully, but these errors were encountered: