-
Notifications
You must be signed in to change notification settings - Fork 37
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
Apply Expression on Input Argument #30
Comments
Seconded. In one of my projects, I find myself wrapping things in a #[derive(new)]
pub struct Foo {
#[new(eval = "Box::new(bar)")] bar: Box<Bar>,
baz: Baz,
} The exact keyword is up for debate: |
A common use-case for me along these lines is making the argument #[derive(new)]
pub struct Person {
#[new(into)]
name: String;
} Another common use-case for me that this feature would help with, but which might also justify dedicated syntax is to clone the input expression. #[derive(new)]
pub struct Shared {
#[new(cloned)]
write: Arc<Something>,
} |
The addition of Not sure about custom expressions, but also a dedicated #[derive(new)]
pub struct Person {
name: String,
#[new(into_iter="&str", owned)]
friends: Vec<String>,
} A specific use case where this optimization would help a lot is constructing resources in |
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.
The text was updated successfully, but these errors were encountered: