You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use workspace.package and workspace.dependencies. The main advantage is sharing the metadata between the related packages. The slightly simpler dependency management is a bonus.
#![feature(adt_const_params)]#[derive(Copy,Clone,Debug,Default)]pubstructLayer<constFIELD:&'static str,T: ?Sized>(T);impl<constFIELD:&'static str,T,U>SerializeAs<T>forLayer<FIELD,U>whereU:SerializeAs<T>,T: ?Sized,U: ?Sized,{fnserialize_as<S>(source:&T,serializer:S) -> Result<S::Ok,S::Error>whereS:Serializer{use serde::ser::SerializeStruct;letmut ser_struct = serializer.serialize_struct("Layer",1)?;
ser_struct.serialize_field(FIELD,&ser::SerializeAsWrap::<T,U>::new(source))?;
ser_struct.end()}}// Can be used like this#[serde_as]#[derive(Serialize)]structData{i:i32,#[serde_as(as = r#"Layer<"extra", Layer<"foobar", Layer<"really_another_one", DisplayFromStr>>>"#)]b:bool,}// or like
serde_json::to_string(&Layer::<"root">(&data))
https://github.com/dtolnay/monostate contains a solution to encode &str into a static type without requiring adt_const_params. It doesn't quite fit the above use case, since the value is not accessible as a &'static str. But Layer could be implemented if it uses serialize_map.
workspace.package
andworkspace.dependencies
. The main advantage is sharing the metadata between the related packages. The slightly simpler dependency management is a bonus.feature(adt_const_params)
Add extra layers for serializing/deserializing. Serialize struct with additional root element #340 (comment)
https://github.com/dtolnay/monostate contains a solution to encode
&str
into a static type without requiringadt_const_params
. It doesn't quite fit the above use case, since the value is not accessible as a&'static str
. ButLayer
could be implemented if it usesserialize_map
.Add a macro-free version of
with_prefix!
.Get rid of the special key name requirement for `KeyValueMap
serde_with/serde_with/src/key_value_map.rs
Lines 210 to 215 in 725d177
feature(array_try_from_fn)
Tracking issue fortry_array_from_fn
rust-lang/rust#89379array_from_iterator
with something from std.Provide a means of turning iterators into fixed-size arrays rust-lang/rust#81615
serde_with/serde_with/src/utils.rs
Lines 119 to 174 in b50b611
The text was updated successfully, but these errors were encountered: