Derive Macro new
Source #[derive(new)]
{
#[new]
}
Expand description
See crate-level docs for a usage and output example.
§Container options
| Opt | Default | Description |
new(const_fn) | false | Whether to make the constructor a const fn |
default | false | Generate a Default implementation if the constructor ends up with no arguments. |
new(vis(visibility)) | pub | The visibility of the constructor |
new(name(ident)) | new | Constructor fn name |
new(comment(literal)) | | A doc comment to add to the constructor |
new(bounds(T: Whatever)) | | Generic type bounds for the implementation |
new(args(foo: u8, bar: String)) | | Additional arguments to add to the beginning of the args list |
§Field options
| Opt | Description |
new(default) | Omit the field from the constructor and use Default |
new(clone) | Make the argument pass-by-reference and clone it |
new(into) | Make the argument Into<T> |
new(name(ident)) | Rename the function argument - useful for newtype structs |
new(val(expr)) | Initialise the value with the following expression instead of a constructor argument |