diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 5fc96d1a4..68c494c42 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -312,7 +312,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result &CallbackApi { todo!() } diff --git a/packages/fermi/src/hooks/atom_ref.rs b/packages/fermi/src/hooks/atom_ref.rs index 74dd9268b..8dbeb2c4d 100644 --- a/packages/fermi/src/hooks/atom_ref.rs +++ b/packages/fermi/src/hooks/atom_ref.rs @@ -13,6 +13,7 @@ use std::{ /// /// /// +#[must_use] pub fn use_atom_ref<'a, T: 'static>( cx: &'a ScopeState, atom: &'static AtomRef, diff --git a/packages/fermi/src/hooks/read.rs b/packages/fermi/src/hooks/read.rs index 57a544e93..c2538c74d 100644 --- a/packages/fermi/src/hooks/read.rs +++ b/packages/fermi/src/hooks/read.rs @@ -2,10 +2,12 @@ use crate::{use_atom_root, AtomId, AtomRoot, Readable}; use dioxus_core::{ScopeId, ScopeState}; use std::rc::Rc; +#[must_use] pub fn use_read(cx: &ScopeState, f: impl Readable) -> &V { use_read_rc(cx, f).as_ref() } +#[must_use] pub fn use_read_rc(cx: &ScopeState, f: impl Readable) -> &Rc { let root = use_atom_root(cx); diff --git a/packages/fermi/src/hooks/set.rs b/packages/fermi/src/hooks/set.rs index 5e5141227..89fe48b0f 100644 --- a/packages/fermi/src/hooks/set.rs +++ b/packages/fermi/src/hooks/set.rs @@ -2,6 +2,7 @@ use crate::{use_atom_root, Writable}; use dioxus_core::ScopeState; use std::rc::Rc; +#[must_use] pub fn use_set(cx: &ScopeState, f: impl Writable) -> &Rc { let root = use_atom_root(cx); cx.use_hook(|| { diff --git a/packages/fermi/src/hooks/state.rs b/packages/fermi/src/hooks/state.rs index 071b18059..d4ebc529c 100644 --- a/packages/fermi/src/hooks/state.rs +++ b/packages/fermi/src/hooks/state.rs @@ -30,6 +30,7 @@ use std::{ /// )) /// } /// ``` +#[must_use] pub fn use_atom_state(cx: &ScopeState, f: impl Writable) -> &AtomState { let root = crate::use_atom_root(cx); diff --git a/packages/fullstack/src/hooks/server_future.rs b/packages/fullstack/src/hooks/server_future.rs index e4d89480e..f8eaef963 100644 --- a/packages/fullstack/src/hooks/server_future.rs +++ b/packages/fullstack/src/hooks/server_future.rs @@ -22,6 +22,7 @@ use std::sync::Arc; /// will be allowed to continue /// /// - dependencies: a tuple of references to values that are PartialEq + Clone +#[must_use = "Consider using `cx.spawn` to run a future without reading its value"] pub fn use_server_future( cx: &ScopeState, dependencies: D, diff --git a/packages/hooks/src/computed.rs b/packages/hooks/src/computed.rs index 3369d6832..dbea75d73 100644 --- a/packages/hooks/src/computed.rs +++ b/packages/hooks/src/computed.rs @@ -37,6 +37,7 @@ use std::{ /// } /// } /// ``` +#[must_use] pub fn use_tracked_state(cx: &ScopeState, init: impl FnOnce() -> T) -> &Tracked { cx.use_hook(|| { let init = init(); @@ -160,6 +161,7 @@ impl Drop for Tracker { } } +#[must_use = "Consider using the `use_effect` hook to rerun an effect whenever the tracked state changes if you don't need the result of the computation"] pub fn use_selector( cx: &ScopeState, tracked: &Tracked, diff --git a/packages/hooks/src/use_callback.rs b/packages/hooks/src/use_callback.rs index 3f223b581..52e592f6b 100644 --- a/packages/hooks/src/use_callback.rs +++ b/packages/hooks/src/use_callback.rs @@ -24,6 +24,7 @@ macro_rules! use_callback { ) }; } + pub fn use_callback(cx: &ScopeState, make: impl FnOnce() -> R) -> impl FnMut(T) + '_ where R: FnMut(T) -> F + 'static, diff --git a/packages/hooks/src/use_context.rs b/packages/hooks/src/use_context.rs index fdf363252..0d94492f6 100644 --- a/packages/hooks/src/use_context.rs +++ b/packages/hooks/src/use_context.rs @@ -3,6 +3,7 @@ use dioxus_core::ScopeState; /// Consume some context in the tree, providing a sharable handle to the value /// /// Does not regenerate the value if the value is changed at the parent. +#[must_use] pub fn use_context(cx: &ScopeState) -> Option<&T> { cx.use_hook(|| cx.consume_context::()).as_ref() } diff --git a/packages/hooks/src/use_coroutine.rs b/packages/hooks/src/use_coroutine.rs index e5563d793..f2577b90c 100644 --- a/packages/hooks/src/use_coroutine.rs +++ b/packages/hooks/src/use_coroutine.rs @@ -79,6 +79,7 @@ where /// Get a handle to a coroutine higher in the tree /// /// See the docs for [`use_coroutine`] for more details. +#[must_use] pub fn use_coroutine_handle(cx: &ScopeState) -> Option<&Coroutine> { cx.use_hook(|| cx.consume_context::>()) .as_ref() diff --git a/packages/hooks/src/use_memo.rs b/packages/hooks/src/use_memo.rs index 3181d57b8..be61b8d53 100644 --- a/packages/hooks/src/use_memo.rs +++ b/packages/hooks/src/use_memo.rs @@ -28,6 +28,7 @@ use crate::UseFutureDep; /// render!(Calculator { number: 0 }) /// } /// ``` +#[must_use = "Consider using `use_effect` to run rerun a callback when dependencies change"] pub fn use_memo(cx: &ScopeState, dependencies: D, callback: impl FnOnce(D::Out) -> T) -> &T where T: 'static, diff --git a/packages/hooks/src/use_ref.rs b/packages/hooks/src/use_ref.rs index cf1b0306f..d0b95074e 100644 --- a/packages/hooks/src/use_ref.rs +++ b/packages/hooks/src/use_ref.rs @@ -110,6 +110,7 @@ use std::{ /// } /// }) /// ``` +#[must_use] pub fn use_ref(cx: &ScopeState, initialize_refcell: impl FnOnce() -> T) -> &UseRef { let hook = cx.use_hook(|| UseRef { update: cx.schedule_update(), diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index 18ce1e5f1..37226c759 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -158,6 +158,7 @@ impl ProvidedStateInner { /// Any time a component calls `write`, every consumer of the state will be notified - excluding the provider. /// /// Right now, there is not a distinction between read-only and write-only, so every consumer will be notified. +#[must_use] pub fn use_shared_state(cx: &ScopeState) -> Option<&UseSharedState> { let state_owner: &mut Option> = &mut *cx.use_hook(move || { let scope_id = cx.scope_id(); diff --git a/packages/hooks/src/use_state.rs b/packages/hooks/src/use_state.rs index a2da3c885..254493510 100644 --- a/packages/hooks/src/use_state.rs +++ b/packages/hooks/src/use_state.rs @@ -30,6 +30,7 @@ use std::{ /// )) /// } /// ``` +#[must_use] pub fn use_state( cx: &ScopeState, initial_state_fn: impl FnOnce() -> T, diff --git a/packages/html/src/eval.rs b/packages/html/src/eval.rs index c90f5125b..292de70fc 100644 --- a/packages/html/src/eval.rs +++ b/packages/html/src/eval.rs @@ -33,6 +33,7 @@ type EvalCreator = Rc Result>; /// parts is practically asking for a hacker to find an XSS vulnerability in /// it. **This applies especially to web targets, where the JavaScript context /// has access to most, if not all of your application data.** +#[must_use] pub fn use_eval(cx: &ScopeState) -> &EvalCreator { &*cx.use_hook(|| { let eval_provider = cx diff --git a/packages/router/src/hooks/use_navigator.rs b/packages/router/src/hooks/use_navigator.rs index c1c21ee63..a05cd036f 100644 --- a/packages/router/src/hooks/use_navigator.rs +++ b/packages/router/src/hooks/use_navigator.rs @@ -48,6 +48,7 @@ use crate::prelude::{Navigator, RouterContext}; /// # let mut vdom = VirtualDom::new(App); /// # let _ = vdom.rebuild(); /// ``` +#[must_use] pub fn use_navigator(cx: &ScopeState) -> &Navigator { &*cx.use_hook(|| { let router = cx diff --git a/packages/router/src/hooks/use_route.rs b/packages/router/src/hooks/use_route.rs index 42cca27fb..51d78cfca 100644 --- a/packages/router/src/hooks/use_route.rs +++ b/packages/router/src/hooks/use_route.rs @@ -46,6 +46,7 @@ use crate::utils::use_router_internal::use_router_internal; /// # let _ = vdom.rebuild(); /// # assert_eq!(dioxus_ssr::render(&vdom), "

App

Current Path

/

") /// ``` +#[must_use] pub fn use_route(cx: &ScopeState) -> Option { match use_router_internal(cx) { Some(r) => Some(r.current()), diff --git a/packages/router/src/hooks/use_router.rs b/packages/router/src/hooks/use_router.rs index 0891ebf97..5f1f13e45 100644 --- a/packages/router/src/hooks/use_router.rs +++ b/packages/router/src/hooks/use_router.rs @@ -3,6 +3,7 @@ use dioxus::prelude::ScopeState; use crate::{prelude::RouterContext, utils::use_router_internal::use_router_internal}; #[deprecated = "prefer the use_navigator or use_route functions"] +#[must_use] /// A hook that provides access to information about the router. pub fn use_router(cx: &ScopeState) -> &RouterContext { use_router_internal(cx) diff --git a/packages/server-macro/src/lib.rs b/packages/server-macro/src/lib.rs index f739490d3..5ad9a682b 100644 --- a/packages/server-macro/src/lib.rs +++ b/packages/server-macro/src/lib.rs @@ -109,7 +109,7 @@ pub fn server(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream { let upper_cammel_case_name = Converter::new() .from_case(Case::Snake) .to_case(Case::UpperCamel) - .convert(&sig.ident.to_string()); + .convert(sig.ident.to_string()); args.struct_name = Some(Ident::new(&upper_cammel_case_name, sig.ident.span())); } let struct_name = args.struct_name.as_ref().unwrap(); diff --git a/packages/signals/src/selector.rs b/packages/signals/src/selector.rs index 346506ff7..91ab920c8 100644 --- a/packages/signals/src/selector.rs +++ b/packages/signals/src/selector.rs @@ -21,6 +21,7 @@ use crate::{get_effect_stack, signal::SignalData, CopyValue, Effect, ReadOnlySig /// render! { "{double}" } /// } /// ``` +#[must_use = "Consider using `use_effect` to rerun a callback when dependencies change"] pub fn use_selector( cx: &ScopeState, f: impl FnMut() -> R + 'static, @@ -44,6 +45,7 @@ pub fn use_selector( /// render! { "{double}" } /// } /// ``` +#[must_use = "Consider using `use_effect` to rerun a callback when dependencies change"] pub fn use_selector_with_dependencies( cx: &ScopeState, dependencies: D, diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index 944bde225..c35b04031 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -44,6 +44,7 @@ use crate::{CopyValue, Effect}; /// } /// } /// ``` +#[must_use] pub fn use_signal(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal { *cx.use_hook(|| Signal::new(f())) }