derive-new icon indicating copy to clipboard operation
derive-new copied to clipboard

derive simple constructor functions for Rust structs

Results 15 derive-new issues
Sort by recently updated
recently updated
newest added

Many times I have MyStruct::new("something".into()). I would rather not keep typing into(). Perhaps there is a way that new can take an Into.

It's sometimes convenient for a constructor to be a `const fn`. Compiling the unit test here fails with: ```rust Compiling derive-new v0.5.9 (/home/ian/src/derive-new) error[E0659]: `new` is ambiguous (derive helper attribute...

> error: calls in constants are limited to constant functions, struct and enum constructors How can I make the generated `new()` constructor *const-fn*? E.g.: ```rust #[derive(new, Copy, Clone)] pub struct...

Today, `#[derive(new)]` always creates a `pub fn`, regardless of the visibility of the struct it's applied to. In Rust 2018, that becomes a lint error, which makes it (at present)...

There's some structures I'd like to use this with, but they require tiny adjustments to input arguments when storing them in the structure, such as [subtracting 1 from an integer](https://github.com/pop-os/distinst/blob/master/src/disk/config/partitions/builder.rs#L22).

Is it possible to name the ctor differently than "new"? I have several use cases where I use the derived `new` only internally in my real ctor that should be...

Currently it will generate false positives on cases like: ```rust struct PhantomData; #[derive(new)] struct Foo { bar: PhantomData } ``` and false negatives on cases like: ```rust use std::marker::PhantomData as...

- [x] test where clauses - [x] tuple structs - [x] stable macros 1.1 - [x] Set up travis build - [ ] Polish up the readme a bit, add...

```rust #[derive(new)] pub struct P String, } /* error: proc-macro derive panicked = help: message: Couldn't parse item: "failed to parse macro input: \"pub struct P String,\\n}\"" */ ``` Another...

bug

If a struct has too many members, `cargo clippy` will complain that the ctor has too many parameters: ``` warning: this function has too many arguments (16/7), #[warn(too_many_arguments)] on by...