default-conversion-rs
Default conversion for structures with same fields of the same name
I discovered this way to do the same job of this crate: https://stackoverflow.com/questions/57477967/how-can-i-use-serde-to-serialize-a-struct-to-another-rust-data-structure
But apparently my way to do it with From is faster : https://github.com/serde-rs/json/issues/724
Why I created this ?
Some projects which use derive proc macros need separates structures with similar "structures" to make different things. For example :
- An API with input structures that have some same fields with the model.
Usage :
default-conversion = "0.1.0"
Example :
Developper code:
;
;
;
;
let a = InputA ;
let b = from;
Expanded code :
;
;
;
;
let a = InputA ;
let b = from;
Complete example in tests/basic_struct.rs
Explanations
Detailed explanations in docs (soon xd).
IntoDefault
is the main derive macro to invoke the from implementation.
IntoStruct
the attribute proc macro to define the type in which we want to implement the conversion. #[IntoStruct(TYPE_OF_STRUCT)]
Supported features:
- Conversion with primitive types.
- Conversion with complex types.
- Auto convert to Option or Object as needed.
- Conversion with vectors of different types
Next steps:
- Examples
- Better tests
- Docs