From 162b033c36e2ff1bf5ca5227e9b8403503516a3a Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 9 Feb 2024 12:23:57 -0600 Subject: [PATCH] provide feature hints for the dioxus crate as well --- packages/core/src/error_boundary.rs | 8 ++++---- packages/core/src/events.rs | 2 +- packages/core/src/lib.rs | 4 ++-- packages/core/src/virtual_dom.rs | 6 +++--- packages/dioxus/Cargo.toml | 3 +++ packages/dioxus/README.md | 23 +++++++++++------------ packages/dioxus/src/launch.rs | 9 +++++++++ packages/dioxus/src/lib.rs | 26 ++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 22 deletions(-) diff --git a/packages/core/src/error_boundary.rs b/packages/core/src/error_boundary.rs index 7fa1d2591..6e1055c6e 100644 --- a/packages/core/src/error_boundary.rs +++ b/packages/core/src/error_boundary.rs @@ -140,12 +140,12 @@ impl ErrorBoundary { /// /// ```rust, ignore /// #[component] -/// fn app( count: String) -> Element { +/// fn app(count: String) -> Element { /// let id: i32 = count.parse().throw()?; /// /// rsx! { /// div { "Count {}" } -/// }) +/// } /// } /// ``` pub trait Throw: Sized { @@ -170,7 +170,7 @@ pub trait Throw: Sized { /// /// rsx! { /// div { "Count {}" } - /// }) + /// } /// } /// ``` fn throw(self) -> Option; @@ -193,7 +193,7 @@ pub trait Throw: Sized { /// /// rsx! { /// div { "Count {}" } - /// }) + /// } /// } /// ``` fn throw_with(self, e: impl FnOnce() -> D) -> Option { diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index 2c0c92d14..7581d0bb6 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -159,7 +159,7 @@ impl std::fmt::Debug for Event { /// button { /// onclick: move |evt| cx.onclick.call(evt), /// } -/// }) +/// } /// } /// /// ``` diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index a55ce4be7..afa80eb84 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -42,7 +42,7 @@ pub(crate) mod innerlude { /// An Errored [`Element`] will propagate the error to the nearest error boundary. pub type Element = Option; - /// A [`Component`] is a function that takes a [`Scope`] and returns an [`Element`]. + /// A [`Component`] is a function that takes [`Properties`] and returns an [`Element`]. /// /// Components can be used in other components with two syntax options: /// - lowercase as a function call with named arguments (rust style) @@ -84,7 +84,7 @@ pub use crate::innerlude::{ /// The purpose of this module is to alleviate imports of many common types /// -/// This includes types like [`Scope`], [`Element`], and [`Component`]. +/// This includes types like [`Element`], and [`Component`]. pub mod prelude { pub use crate::innerlude::{ consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, flush_sync, diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 75ce4ffc7..b45a4ecaa 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -24,7 +24,7 @@ use std::{any::Any, collections::BTreeSet, rc::Rc}; /// /// ## Guide /// -/// Components are defined as simple functions that take [`Scope`] and return an [`Element`]. +/// Components are defined as simple functions that take [`crate::properties::Properties`] and return an [`Element`]. /// /// ```rust /// # use dioxus::prelude::*; @@ -218,7 +218,7 @@ impl VirtualDom { /// # Example /// ```rust, ignore /// fn Example() -> Element { - /// rsx!( div { "hello world" } )) + /// rsx!( div { "hello world" } ) /// } /// /// let dom = VirtualDom::new(Example); @@ -526,7 +526,7 @@ impl VirtualDom { /// /// # Example /// ```rust, ignore - /// static app: Component = |cx| rsx!{ "hello world" }); + /// static app: Component = |cx| rsx!{ "hello world" }; /// /// let mut dom = VirtualDom::new(); /// let edits = dom.rebuild(); diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index fa1d2a4f6..b808bdc85 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -55,6 +55,9 @@ warp = ["dioxus-fullstack?/warp", "ssr", "dioxus-liveview?/warp"] rocket = ["dioxus-liveview?/rocket"] tui = ["dioxus-tui", "dioxus-config-macro/tui"] +# This feature enables some nightly flags that make it more clear what structs/methods are available in each feature +nightly-doc = [] + [dev-dependencies] futures-util = { workspace = true } tracing = { workspace = true } diff --git a/packages/dioxus/README.md b/packages/dioxus/README.md index 210ea77c3..ebd2cdb90 100644 --- a/packages/dioxus/README.md +++ b/packages/dioxus/README.md @@ -50,7 +50,7 @@ fn main() { // It's not required, but highly recommended. For example, UpperCamelCase components will not generate a warning. #[component] fn App() -> Element { - rsx!("hello world!")) + rsx!("hello world!") } ``` @@ -97,13 +97,12 @@ If we want to omit the boilerplate of `cx.render`, we can simply pass in render nodes in match statements. ```rust, ignore -#[component[ +#[component] fn Example() -> Element { - // both of these are equivalent - rsx!("hello world")) + rsx!("hello world"); - rsx!("hello world!") + rsx!("hello world!"); } ``` @@ -127,7 +126,7 @@ fn App() -> Element { )) } - )) + ) } ``` @@ -147,7 +146,7 @@ fn App() -> Element { title: "My App", color: "red", } - )) + ) } ``` @@ -169,7 +168,7 @@ fn Header(cx: Scope) -> Element { background_color: "{cx.props.color}" h1 { "{cx.props.title}" } } - )) + ) } ``` @@ -184,7 +183,7 @@ fn Header(title: String, color: String) -> Element { background_color: "{color}" h1 { "{title}" } } - )) + ) } ``` @@ -201,13 +200,13 @@ struct HeaderProps<'a> { } #[component] -fn Header(props: HeaderProps -> Element { +fn Header(props: HeaderProps) -> Element { rsx!( div { background_color: "{cx.props.color}" h1 { "{cx.props.title}" } } - )) + ) } ``` @@ -299,7 +298,7 @@ fn App() -> Element { div { "Count: {count}" } button { onclick: move |_| count.set(count + 1), "Increment" } button { onclick: move |_| count.set(count - 1), "Decrement" } - )) + ) } ``` diff --git a/packages/dioxus/src/launch.rs b/packages/dioxus/src/launch.rs index 3b49eb97a..63b2183e2 100644 --- a/packages/dioxus/src/launch.rs +++ b/packages/dioxus/src/launch.rs @@ -38,6 +38,7 @@ impl LaunchBuilder { /// Launch your web application. #[cfg(feature = "web")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "web")))] pub fn web() -> LaunchBuilder { LaunchBuilder { launch_fn: dioxus_web::launch::launch, @@ -48,6 +49,7 @@ impl LaunchBuilder { /// Launch your desktop application. #[cfg(feature = "desktop")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "desktop")))] pub fn desktop() -> LaunchBuilder { LaunchBuilder { launch_fn: dioxus_desktop::launch::launch, @@ -58,6 +60,7 @@ impl LaunchBuilder { /// Launch your fullstack application. #[cfg(feature = "fullstack")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "fullstack")))] pub fn fullstack() -> LaunchBuilder { LaunchBuilder { launch_fn: dioxus_fullstack::launch::launch, @@ -68,6 +71,7 @@ impl LaunchBuilder { /// Launch your fullstack application. #[cfg(feature = "mobile")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "mobile")))] pub fn mobile() -> LaunchBuilder { LaunchBuilder { launch_fn: dioxus_mobile::launch::launch, @@ -77,6 +81,7 @@ impl LaunchBuilder { } #[cfg(feature = "tui")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "tui")))] /// Launch your tui application pub fn tui() -> LaunchBuilder { LaunchBuilder { @@ -209,24 +214,28 @@ pub fn launch(app: fn() -> Element) { } #[cfg(feature = "web")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "web")))] /// Launch your web application without any additional configuration. See [`LaunchBuilder`] for more options. pub fn launch_web(app: fn() -> Element) { LaunchBuilder::web().launch(app) } #[cfg(feature = "desktop")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "desktop")))] /// Launch your desktop application without any additional configuration. See [`LaunchBuilder`] for more options. pub fn launch_desktop(app: fn() -> Element) { LaunchBuilder::desktop().launch(app) } #[cfg(feature = "fullstack")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "fullstack")))] /// Launch your fullstack application without any additional configuration. See [`LaunchBuilder`] for more options. pub fn launch_fullstack(app: fn() -> Element) { LaunchBuilder::fullstack().launch(app) } #[cfg(feature = "tui")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "tui")))] /// Launch your tui application without any additional configuration. See [`LaunchBuilder`] for more options. pub fn launch_tui(app: fn() -> Element) { LaunchBuilder::tui().launch(app) diff --git a/packages/dioxus/src/lib.rs b/packages/dioxus/src/lib.rs index fd052dfc2..d843cfd56 100644 --- a/packages/dioxus/src/lib.rs +++ b/packages/dioxus/src/lib.rs @@ -1,88 +1,114 @@ #![doc = include_str!("../README.md")] #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")] #![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")] +#![cfg_attr(any(docsrs, feature = "nightly-doc"), feature(doc_cfg))] pub use dioxus_core; #[cfg(feature = "launch")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "launch")))] mod launch; #[cfg(feature = "hooks")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "hooks")))] pub use dioxus_hooks as hooks; #[cfg(feature = "signals")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "signals")))] pub use dioxus_signals as signals; pub mod events { #[cfg(feature = "html")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "html")))] pub use dioxus_html::prelude::*; } #[cfg(feature = "html")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "html")))] pub use dioxus_html as html; #[cfg(feature = "macro")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "macro")))] pub use dioxus_core_macro as core_macro; pub mod prelude { #[cfg(feature = "launch")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "launch")))] pub use crate::launch::*; #[cfg(feature = "hooks")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "hooks")))] pub use crate::hooks::*; #[cfg(feature = "signals")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "signals")))] pub use dioxus_signals::*; pub use dioxus_core::prelude::*; #[cfg(feature = "macro")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "macro")))] #[allow(deprecated)] pub use dioxus_core_macro::{component, format_args_f, inline_props, render, rsx, Props}; #[cfg(feature = "launch")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "launch")))] pub use dioxus_config_macro::*; #[cfg(feature = "html")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "html")))] pub use dioxus_html as dioxus_elements; #[cfg(feature = "html")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "html")))] pub use dioxus_elements::{prelude::*, GlobalAttributes, SvgAttributes}; #[cfg(all(not(target_arch = "wasm32"), feature = "hot-reload"))] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "hot-reload")))] pub use dioxus_hot_reload::{self, hot_reload_init}; pub use dioxus_core; #[cfg(feature = "fullstack")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "fullstack")))] pub use dioxus_fullstack::prelude::*; #[cfg(feature = "router")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "router")))] pub use dioxus_router; #[cfg(feature = "router")] + #[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "router")))] pub use dioxus_router::prelude::*; } #[cfg(feature = "web")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "web")))] pub use dioxus_web as web; #[cfg(feature = "router")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "router")))] pub use dioxus_router as router; #[cfg(feature = "fullstack")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "fullstack")))] pub use dioxus_fullstack as fullstack; #[cfg(feature = "desktop")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "desktop")))] pub use dioxus_desktop as desktop; #[cfg(feature = "mobile")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "mobile")))] pub use dioxus_desktop as mobile; #[cfg(feature = "liveview")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "liveview")))] pub use dioxus_liveview as liveview; #[cfg(feature = "tui")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "tui")))] pub use dioxus_tui as tui; #[cfg(feature = "ssr")] +#[cfg_attr(any(docsrs, feature = "nightly-doc"), doc(cfg(feature = "ssr")))] pub use dioxus_ssr as ssr;