Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiskai/constructor-macro
https://github.com/thiskai/constructor-macro
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/thiskai/constructor-macro
- Owner: thisKai
- License: mit
- Created: 2019-06-08T17:33:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-01T00:24:48.000Z (over 4 years ago)
- Last Synced: 2024-10-12T23:42:25.549Z (about 1 month ago)
- Language: Rust
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# constructor-macro
## Cargo.toml
```toml
[dependencies]
constructor-macro = "0.4"
```## Example
### Rust 2018
```rust
use constructor_macro::ConstructorMacro;#[derive(ConstructorMacro)]
pub struct Thing {
#[default(1)]
pub field1: i32,
pub field2: i32,
}fn main() {
let thing1 = Thing!();
assert_eq!(thing1.field1, 1);
assert_eq!(thing1.field2, 0);let thing2 = Thing! { field1: 2 };
assert_eq!(thing2.field1, 2);
assert_eq!(thing2.field2, 0);let thing3 = Thing! {
field1: 0,
field2: 100,
};
assert_eq!(thing3.field1, 0);
assert_eq!(thing3.field2, 100);
}
```### Rust 2015
```rust
#[macro_use]
extern crate constructor_macro;...
```