| Crates.io | constructor-lite |
| lib.rs | constructor-lite |
| version | 0.3.0 |
| created_at | 2023-02-26 17:38:31.197646+00 |
| updated_at | 2024-03-14 20:58:10.65988+00 |
| description | Generate minimal constructors for structs |
| homepage | |
| repository | https://github.com/d-k-bo/constructor-lite |
| max_upload_size | |
| id | 795369 |
| size | 16,377 |
This crate provides the ConstructorLite derive macro for generating
minimal constructors for a struct from its fields.
It is primarily designed for structs where deriving [Default] is not
possible because some fields don't implement it.
By default, an associated function new() is generated, which expects every
field that is not Option<T> as an argument.
#[constructor(required)].Default from the constructor
function, it can be marked with #[constructor(default)].#[constructor(name = "function_name")].#[constructor(visibility = "pub(super)")].For more advanced uses you might prefer using
derive-new or
derive_builder instead.
use constructor_lite::ConstructorLite;
#[derive(Debug, PartialEq, ConstructorLite)]
struct Movie {
title: String,
year: Option<u16>,
}
assert_eq!(
Movie::new("Star Wars".to_owned()),
Movie { title: "Star Wars".to_owned(), year: None },
)
This project is licensed under the MIT License.
See LICENSE for more information.