1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Router-related helpers used by components that optionally render a
//! [`dioxus_router::components::Link`] when the `router` feature is enabled.
//!
//! The main type here is [`MaybeNav`], a thin wrapper around
//! `Option<NavigationTarget>` that, combined with `#[props(into)]`, lets users
//! pass any value that implements `Into<NavigationTarget>` (such as a
//! `Routable` `Route` enum variant) directly to a `to` prop without having to
//! wrap it in `Some(...)` and call `.into()` themselves.
//!
//! Addresses [issue #6](https://github.com/rexlunae/dioxus-bulma/issues/6).
//!
//! # Example
//!
//! ```rust,ignore
//! use dioxus::prelude::*;
//! use dioxus_bulma::prelude::*;
//!
//! #[derive(Routable, Clone, PartialEq)]
//! enum Route {
//! #[route("/")]
//! Home,
//! #[route("/devices")]
//! DeviceList,
//! }
//!
//! rsx! {
//! // Route::DeviceList works directly thanks to MaybeNav.
//! MenuItem { to: Route::DeviceList, "Devices" }
//! }
//! ```
use NavigationTarget;
/// Optional [`NavigationTarget`] wrapper that allows ergonomic conversion from
/// any `T: Into<NavigationTarget>` (including `Routable` enum variants) via
/// `#[props(into)]` on a Dioxus component prop.
;
// Blanket conversion: anything that already converts into `NavigationTarget`
// — including `NavigationTarget` itself (via the standard reflexive
// `Into<T> for T`) and any `Routable` route — converts into `MaybeNav` as
// `Some(target)`. This impl is what lets `to: Route::DeviceList` "just work".