DioxusLabs / DioxusLabs/dioxus

SuperFrom for more optional prop types including custom types

Open
#3,476 3 comments 0 reactions 0 assignees View on GitHub
core enhancement
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

## Feature Request

So right now, as of v0.6.1, optional component props are only supported for specific types when also using `#[props(into)]`. It would be helpful if it was also usable with `Option` given the custom type meets the prop requirements.

I currently wrote a custom `Option` that implements `SuperFrom` for any inner type that implements `Into` for the target type. This would mean something like this would work.

```rust
use dioxus::prelude::*;

#[component]
fn Custom(
#[props(into)]
state: Option
) -> Element {
VNode::empty()
}
```

Currently, there is an error since `SuperFrom` is not implemented for `Option`

## Implement Suggestion

Something like the snippet below may work. This would also mean that it would be implemented for anything that implements `From` or `Into` between the types. If this isn't desired, then maybe a new Trait that can be derived to convert between the types and would automatically allow it to be used as a prop in `Option`

```rust
pub struct OptionFromValue;
impl, U> SuperFrom for Option {
fn super_from(value: T) -> Self {
Some(Into::::into(value))
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.