3 unstable releases

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

#2680 in Rust patterns

Download history 128/week @ 2024-11-20 109/week @ 2024-11-27 124/week @ 2024-12-04 207/week @ 2024-12-11 87/week @ 2024-12-18 35/week @ 2024-12-25 102/week @ 2025-01-01 128/week @ 2025-01-08 147/week @ 2025-01-15 197/week @ 2025-01-22 223/week @ 2025-01-29 237/week @ 2025-02-05 222/week @ 2025-02-12 194/week @ 2025-02-19 238/week @ 2025-02-26 117/week @ 2025-03-05

789 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

~220–660KB
~16K SLoC