Skip to content

Implicitly convert value to Some(value) for Option<T> props #1604

@ranile

Description

@ranile

Describe the feature you'd like
Implicitly converting value to Some(value) for a prop with type of Option<T>. Consider the following props

struct Props {
    #[prop_or_default]
    pub foo: Option<String>
}

If no prop value is passed for foo then that field will be initialized as None but when a value is to be passed, it must be passed as foo=Some(value). It should be able to be passed as foo=value where value has a type of String (&str) and an implicit conversion should occur which converts to Some(value). This is similar to conversion between String and &str.

Is your feature request related to a problem? Please describe.
Converting to Some when passing value to Option<T> props can get repetitive and can be abstracted away similar to conversion between String and &str.

Describe alternatives you've considered
Doing Some(value) every single time.

Additional context
None, that I can think of.

Questionnaire

  • I'm interested in implementing this myself but don't know where to start
  • I would like to add this feature
  • I don't have time to add this right now, but maybe later
    ...and also my knowledge of proc macros is too limited to efficiently work on this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions