3 unstable releases

0.2.1 Dec 16, 2023
0.2.0 May 30, 2022
0.1.0 Apr 4, 2022

#1118 in Rust patterns

Download history 43/week @ 2023-12-22 33/week @ 2023-12-29 46/week @ 2024-01-05 38/week @ 2024-01-12 33/week @ 2024-01-19 37/week @ 2024-01-26 38/week @ 2024-02-02 45/week @ 2024-02-09 64/week @ 2024-02-16 84/week @ 2024-02-23 78/week @ 2024-03-01 87/week @ 2024-03-08 74/week @ 2024-03-15 56/week @ 2024-03-22 133/week @ 2024-03-29 164/week @ 2024-04-05

441 downloads per month

MIT license

11KB
122 lines

Inter-struct provides various derive macros to implement traits between arbitrary structs.

The current available derive macros are:

  • StructMerge
  • StructMergeRef
  • StructInto
  • StructDefault

The general way to use such a derive macro is like this:

#[derive(StructInto)]
#[struct_into(["crate::path_to::TargetStruct"])]
pub struct Test {
    pub test: String,
}

This example generates an impl Into<TargetStruct> for Test, which converts Test into some TargetStruct.

Note that the target struct's paths has to be

  • contained in this crate.
  • relative to the current crate.

Either a single path or a list of paths can be specified. The traits will then be implemented for each given target struct.

#[struct_into("crate::path_to::TargetStruct")]
// or
#[struct_into(["crate::path_to::TargetStruct", "crate::path_to::AnotherTargetStruct"])]

Each derive macro can have their own options, so please check the individual docs for each derive macro in this crate.

Dependencies

~285–730KB
~17K SLoC