https://github.com/panicbit/derive_constructor
https://github.com/panicbit/derive_constructor
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/panicbit/derive_constructor
- Owner: panicbit
- Created: 2021-09-26T17:27:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-26T17:28:44.000Z (over 4 years ago)
- Last Synced: 2025-12-25T21:14:18.682Z (6 months ago)
- Language: Rust
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# derive-constructor
This crate provides a derive macro `Constructor`, which creates a silly trait that mirrors an enum's constructors. It allows constructing an enum without explicitly naming its type.
The generated trait has the same name as the enum but with the suffix `Constructor`.
## Example
```rust
use derive_constructor::Constructor;
#[derive(Constructor, Debug)]
enum Foo {
A,
B(i32)
}
fn main() {
print_foo(<_>::A);
print_foo(<_>::B(42));
}
fn print_foo(foo: Foo) {
println!("{:?}", foo);
}
```