Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: ::new(_) should support .into() #43

Open
zutils opened this issue Jul 16, 2019 · 2 comments
Open

Feature Request: ::new(_) should support .into() #43

zutils opened this issue Jul 16, 2019 · 2 comments

Comments

@zutils
Copy link

zutils commented Jul 16, 2019

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.

@nathan-at-least
Copy link

I came to make the same suggestion.

However, I also prefer precision and explicitness, so I wouldn't recommend always supporting Into on every new param. Here are some brainstorms about design:

A per-struct style configuration

The default style equivalent to the current direct/concrete argument types, then a style called "Into" is introduced:

#[derive(new)]
#[new(style="Into")]
struct Account {
  name: String,
  info: Box<Address>,
}

let acct = Account::new("alice", Address::new());

Per-field configuration

#[derive(new)]
struct Account {
  #[new(style="Into")]
  name: String,
  info: Box<Address>,
}

let acct = Account::new("alice", Address::new()); // Error: expected `Box<Address>` found `Address`

My preference is to support both struct-scoped and per-field configurations. Struct-scoped reduces boilerplate, whereas per-field allows fined-grained precision.

@OmarTawfik
Copy link
Contributor

I implemented the feature in #65 (first time contributor to this crate). Please let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants