Преглед на файлове

provide feature hints for the dioxus crate as well

Evan Almloff преди 1 година
родител
ревизия
162b033c36

+ 4 - 4
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<S = ()>: Sized {
@@ -170,7 +170,7 @@ pub trait Throw<S = ()>: Sized {
     ///
     ///     rsx! {
     ///         div { "Count {}" }
-    ///     })
+    ///     }
     /// }
     /// ```
     fn throw(self) -> Option<Self::Out>;
@@ -193,7 +193,7 @@ pub trait Throw<S = ()>: Sized {
     ///
     ///     rsx! {
     ///         div { "Count {}" }
-    ///     })
+    ///     }
     /// }
     /// ```
     fn throw_with<D: Debug + 'static>(self, e: impl FnOnce() -> D) -> Option<Self::Out> {

+ 1 - 1
packages/core/src/events.rs

@@ -159,7 +159,7 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
 ///         button {
 ///             onclick: move |evt| cx.onclick.call(evt),
 ///         }
-///     })
+///     }
 /// }
 ///
 /// ```

+ 2 - 2
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<VNode>;
 
-    /// 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,

+ 3 - 3
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();

+ 3 - 0
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 }

+ 11 - 12
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<HeaderProps>) -> 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" }
-    ))
+    )
 }
 ```
 

+ 9 - 0
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<dioxus_web::Config, UnsendContext> {
         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<dioxus_desktop::Config, UnsendContext> {
         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<dioxus_fullstack::Config, SendContext> {
         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<dioxus_mobile::Config, UnsendContext> {
         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<dioxus_tui::Config, UnsendContext> {
         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)

+ 26 - 0
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;