#traits-structs #struct #proc-macro #merge #library

inter-struct

Automatically generated traits for arbitrary structs

3 unstable releases

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

#2443 in Rust patterns

Download history 105/week @ 2024-10-24 164/week @ 2024-10-31 105/week @ 2024-11-07 94/week @ 2024-11-14 126/week @ 2024-11-21 112/week @ 2024-11-28 121/week @ 2024-12-05 207/week @ 2024-12-12 76/week @ 2024-12-19 37/week @ 2024-12-26 112/week @ 2025-01-02 128/week @ 2025-01-09 153/week @ 2025-01-16 205/week @ 2025-01-23 270/week @ 2025-01-30 160/week @ 2025-02-06

806 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

~210–650KB
~15K SLoC