#typescript #proc-macro #definition #compose #type #style #import

macro composite_types

Compose type definitions in the style of typescript

2 releases

0.1.1 Nov 5, 2023
0.1.0 Nov 5, 2023

#1053 in Data structures

21 downloads per month

MIT/Apache

50KB
1K SLoC

composite_types

Introducing type definitions in the style of Typescript to Rust!

use proc_macro_def::{compose_type};
struct FieldType {}
mod module { 
    compose_type! {
        struct Example {
            field: Option<FieldType>
        }
        struct MyStruct = Required(Example);
        struct MyStruct2 = Optional(MyStruct);
        pub struct MyStruct3 = Required(MyStruct);
    }

    const EXAMPLE: MyStruct = MyStruct2 {
        field: None
    };
}

struct Example2 {
    field: Option<MyStruct3>
}

Usage

  1. Use the compose_type! macro
  2. Import and define any types outside compose_type! as you normally would
  3. You can reference these types within compose_type!, but cannot compose with them
  4. Define structs within compose_type! to be used to compose new types
  5. Reference your new types outside of compose_type! and use them in your project

Dependencies

~4–5.5MB
~117K SLoC