-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Description
Hi!
I stumbled around some confusing behaviour with regards to no_std builds:
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
struct Testing<'a> {
#[serde(with = "serde_bytes")]
testing: &'a [u8],
}Compiles if the std or alloc feature is enabled, but doesn't compile if it isn't.
I do not understand why the deserialize function is behind such a feature flag.
I understand that serde_bytes only changes the serialization of &[u8] since serde's implementation is already optimized, so you can get around the issue with
#[derive(Deserialize, Serialize)]
struct Testing<'a> {
#[serde(serialize_with = "serde_bytes::serialize")]
testing: &'a [u8],
}But:
- That is counter intuitive, since the doc's main example uses
#[serde(with = "serde_bytes")] - It is more verbose
- I do not understand why this should be gated behind the requirement of an allocator.
- The error confusing since
rustccan't understand the problem (though recent version do correctly point out the feature flag).
Can this feature-gate be removed?
Thanks
Metadata
Metadata
Assignees
Labels
No labels