composite_types

Crates.iocomposite_types
lib.rscomposite_types
version0.1.1
sourcesrc
created_at2023-11-05 01:44:03.642454
updated_at2023-11-05 01:46:41.053564
descriptionCompose type definitions in the style of typescript.
homepage
repositoryhttps://github.com/zb3qk/type_combinations
max_upload_size
id1025706
size49,201
(zb3qk)

documentation

https://docs.rs/composite_types/

README

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
Commit count: 13

cargo fmt