diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index b056a9590..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,171 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## Unreleased - -### Commit Statistics - - - - - 1 commit contributed to the release over the course of 7 calendar days. - - 0 commits where understood as [conventional](https://www.conventionalcommits.org). - - 0 issues like '(#ID)' where seen in commit messages - -### Commit Details - - - -
view details - - * **Uncategorized** - - Fix various typos and grammar nits ([`9e4ec43`](https://github.comgit//DioxusLabs/dioxus/commit/9e4ec43b1e78d355c56a38e4c092170b2b01b20d)) -
- -## v0.1.7 (2022-01-08) - -### Bug Fixes - - - tests - -### Commit Statistics - - - - - 1 commit contributed to the release over the course of 2 calendar days. - - 1 commit where understood as [conventional](https://www.conventionalcommits.org). - - 0 issues like '(#ID)' where seen in commit messages - -### Commit Details - - - -
view details - - * **Uncategorized** - - tests ([`bd341f5`](https://github.comgit//DioxusLabs/dioxus/commit/bd341f5571580cdf5e495379b49ca988fd9211c3)) -
- -## v0.1.1 (2021-12-15) - -### Documentation - - - update local examples and docs to support new syntaxes - - improve docs - - big updates to the reference - - lib.rs docs - - move around examples - -### New Features - - - it compiles once more - - massage lifetimes - - amazingly awesome error handling - - svgs working in webview - - mvoe away from compound context - - more suspended nodes! - - add aria - - enable arbitrary body in rsx! macro - -## v0.1.0 (2021-12-15) - -### Documentation - - - update local examples and docs to support new syntaxes - - improve docs - - big updates to the reference - - lib.rs docs - - move around examples - -### New Features - - - it compiles once more - - massage lifetimes - - amazingly awesome error handling - - svgs working in webview - - mvoe away from compound context - - more suspended nodes! - - add aria - - enable arbitrary body in rsx! macro - -## v0.0.1 (2022-01-03) - -### Documentation - - - improve docs - - update local examples and docs to support new syntaxes - - big updates to the reference - - lib.rs docs - - move around examples - -### New Features - - - it compiles once more - - massage lifetimes - - amazingly awesome error handling - - svgs working in webview - - mvoe away from compound context - - more suspended nodes! - - add aria - - enable arbitrary body in rsx! macro - -### Commit Statistics - - - - - 40 commits contributed to the release over the course of 193 calendar days. - - 38 commits where understood as [conventional](https://www.conventionalcommits.org). - - 0 issues like '(#ID)' where seen in commit messages - -### Commit Details - - - -
view details - - * **Uncategorized** - - remove runner on hook and then update docs ([`d156045`](https://github.comgit//DioxusLabs/dioxus/commit/d1560450bac55f9566e00e00ea405bd1c70b57e5)) - - polish some more things ([`1496102`](https://github.comgit//DioxusLabs/dioxus/commit/14961023f927b3a8bde83cfc7883aa8bfcca9e85)) - - upgrade hooks ([`b3ac2ee`](https://github.comgit//DioxusLabs/dioxus/commit/b3ac2ee3f76549cd1c7b6f9eee7e3382b07d873c)) - - docs ([`8814977`](https://github.comgit//DioxusLabs/dioxus/commit/8814977eeebe06748a3b9677a8070e42a037ebd7)) - - prepare to change our fragment pattern. Add some more docs ([`2c3a046`](https://github.comgit//DioxusLabs/dioxus/commit/2c3a0464264fa11e8100df025d863931f9606cdb)) - - it compiles once more ([`8acdd2e`](https://github.comgit//DioxusLabs/dioxus/commit/8acdd2ea830b995b608d8bac2ef527db8d40e662)) - - some docs and suspense ([`93d4b8c`](https://github.comgit//DioxusLabs/dioxus/commit/93d4b8ca7c1b133e5dba2a8dc9a310dbe1357001)) - - docs and router ([`a5f05d7`](https://github.comgit//DioxusLabs/dioxus/commit/a5f05d73acc0e47b05cff64a373482519414bc7c)) - - Merge branch 'master' into jk/remove_node_safety ([`db00047`](https://github.comgit//DioxusLabs/dioxus/commit/db0004758c77331cc3b93ea8cf227c060028e12e)) - - improve docs ([`7800744`](https://github.comgit//DioxusLabs/dioxus/commit/78007445f944f259170307d840e0f16242b7b4b6)) - - Various typos/grammar/rewording ([`5747e00`](https://github.comgit//DioxusLabs/dioxus/commit/5747e00b27b1b69c4f9c2820e7e78030feaff71e)) - - bubbling in progress ([`a21020e`](https://github.comgit//DioxusLabs/dioxus/commit/a21020ea575e467ba0d608737269fe1b0792dba7)) - - update local examples and docs to support new syntaxes ([`4de16c4`](https://github.comgit//DioxusLabs/dioxus/commit/4de16c4779648e591b3869b5df31271ae603c812)) - - massage lifetimes ([`9726a06`](https://github.comgit//DioxusLabs/dioxus/commit/9726a065b0d4fb1ede5b53a2ddd58c855e51539f)) - - major cleanups to scheduler ([`2933e4b`](https://github.comgit//DioxusLabs/dioxus/commit/2933e4bc11b3074c2bde8d76ec55364fca841988)) - - threadsafe ([`82953f2`](https://github.comgit//DioxusLabs/dioxus/commit/82953f2ac37913f83a822333acd0c47e20777d31)) - - move macro crate out of core ([`7bdad1e`](https://github.comgit//DioxusLabs/dioxus/commit/7bdad1e2e6f67e74c9f67dde2150140cf8a090e8)) - - amazingly awesome error handling ([`4a72b31`](https://github.comgit//DioxusLabs/dioxus/commit/4a72b3140bd244da602deada1eeecded65ff5848)) - - some ideas ([`05c909f`](https://github.comgit//DioxusLabs/dioxus/commit/05c909f320765aec1bf4c1c55ca59ffd5525a2c7)) - - big updates to the reference ([`583fdfa`](https://github.comgit//DioxusLabs/dioxus/commit/583fdfa5618e11d660985b97e570d4503be2ff49)) - - docs, html! macro, more ([`caf772c`](https://github.comgit//DioxusLabs/dioxus/commit/caf772cf249d2f56c8d0b0fa2737ad48e32c6e82)) - - cleanup workspace ([`8f0bb5d`](https://github.comgit//DioxusLabs/dioxus/commit/8f0bb5dc5bfa3e775af567c4b569622cdd932af1)) - - svgs working in webview ([`3bedcb9`](https://github.comgit//DioxusLabs/dioxus/commit/3bedcb93cacec5bdf134adc38ff02eadbf96c1c6)) - - mvoe away from compound context ([`a2c7d17`](https://github.comgit//DioxusLabs/dioxus/commit/a2c7d17b0595769f60bc1c2bbf7cbe32cec37486)) - - more suspended nodes! ([`de9f61b`](https://github.comgit//DioxusLabs/dioxus/commit/de9f61bcf48c0d6e35e46c337b72a713c9f9f7d2)) - - add aria ([`4091846`](https://github.comgit//DioxusLabs/dioxus/commit/4091846934b4b3b2bc03d3ca8aaf7712aebd4e36)) - - more examples ([`56e7eb8`](https://github.comgit//DioxusLabs/dioxus/commit/56e7eb83a97ebd6d5bcd23464cfb9d718e5ac26d)) - - more refactor for async ([`975fa56`](https://github.comgit//DioxusLabs/dioxus/commit/975fa566f9809f8fa2bb0bdb07fbfc7f855dcaeb)) - - enable arbitrary body in rsx! macro ([`7aec40d`](https://github.comgit//DioxusLabs/dioxus/commit/7aec40d57e78ec13ff3a90ca8149521cbf1d9ff2)) - - move CLI into its own "studio" app ([`fd79335`](https://github.comgit//DioxusLabs/dioxus/commit/fd7933561fe81922e4d5d77f6ac3b6f19efb5a90)) - - move some examples around ([`98a0933`](https://github.comgit//DioxusLabs/dioxus/commit/98a09339fd3190799ea4dd316908f0a53fdf2413)) - - fix issues with lifetimes ([`a38a81e`](https://github.comgit//DioxusLabs/dioxus/commit/a38a81e1290375cae685f7c49d3745e4298fab26)) - - more examples ([`11f89e5`](https://github.comgit//DioxusLabs/dioxus/commit/11f89e5d338d14a7aeece0a6275c24ae65913ce7)) - - lib.rs docs ([`bf21c82`](https://github.comgit//DioxusLabs/dioxus/commit/bf21c82de04e25daee60a06232b9a16b640508f2)) - - rename ctx to cx ([`81382e7`](https://github.comgit//DioxusLabs/dioxus/commit/81382e7044fb3dba61d4abb1e6086b7b29143116)) - - move around examples ([`70cd46d`](https://github.comgit//DioxusLabs/dioxus/commit/70cd46dbb2a689ae2d512e142b8aee9c80798430)) - - start moving events to rc ([`b9ff95f`](https://github.comgit//DioxusLabs/dioxus/commit/b9ff95fa12c46365fe73b64a4926a506d5da2342)) - - rename recoil to atoms ([`36ea39a`](https://github.comgit//DioxusLabs/dioxus/commit/36ea39ae30aa3f1fb2d718c0fdf08850c6bfd3ac)) - - more examples and docs ([`7fbaf69`](https://github.comgit//DioxusLabs/dioxus/commit/7fbaf69cabbdde712bb3fd9e4b2a5dc18b9390e9)) - - docs ([`f5683a2`](https://github.comgit//DioxusLabs/dioxus/commit/f5683a23464992ecace463a61414795b5a2c58c8)) -
- diff --git a/examples/query_segments_demo/src/main.rs b/examples/query_segments_demo/src/main.rs index d9f5f83ef..aafcc0f43 100644 --- a/examples/query_segments_demo/src/main.rs +++ b/examples/query_segments_demo/src/main.rs @@ -35,7 +35,7 @@ impl Display for BlogQuerySegments { } } -/// The query segment is anything that implements https://docs.rs/dioxus-router/latest/dioxus_router/routable/trait.FromQuery.html. You can implement that trait for a struct if you want to parse multiple query parameters. +/// The query segment is anything that implements . You can implement that trait for a struct if you want to parse multiple query parameters. impl FromQuery for BlogQuerySegments { fn from_query(query: &str) -> Self { let mut name = None; diff --git a/packages/autofmt/src/lib.rs b/packages/autofmt/src/lib.rs index 8ec33f0f0..64a342885 100644 --- a/packages/autofmt/src/lib.rs +++ b/packages/autofmt/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + use std::fmt::{Display, Write}; use crate::writer::*; diff --git a/packages/check/README.md b/packages/check/README.md index 0bb6ce0a4..6375a8316 100644 --- a/packages/check/README.md +++ b/packages/check/README.md @@ -6,7 +6,7 @@ [![Discord chat][discord-badge]][discord-url] [crates-badge]: https://img.shields.io/crates/v/dioxus-autofmt.svg -[crates-url]: https://crates.io/crates/dioxus-autofmt +[crates-url]: https://crates.io/crates/dioxus-check [mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg [mit-url]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE [actions-badge]: https://github.com/dioxuslabs/dioxus/actions/workflows/main.yml/badge.svg @@ -16,7 +16,7 @@ [Website](https://dioxuslabs.com) | [Guides](https://dioxuslabs.com/learn/0.4/) | -[API Docs](https://docs.rs/dioxus-autofmt/latest/dioxus_autofmt) | +[API Docs](https://docs.rs/dioxus-check) | [Chat](https://discord.gg/XgGxMSkvUM) ## Overview diff --git a/packages/check/src/lib.rs b/packages/check/src/lib.rs index 3870fb610..43a164514 100644 --- a/packages/check/src/lib.rs +++ b/packages/check/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + mod check; mod issues; mod metadata; 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/fermi/src/lib.rs b/packages/fermi/src/lib.rs index 4943e38a3..52bf4cd09 100644 --- a/packages/fermi/src/lib.rs +++ b/packages/fermi/src/lib.rs @@ -1,4 +1,6 @@ #![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")] pub mod prelude { pub use crate::*; 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/generational-box/README.md b/packages/generational-box/README.md index 5ab7926ba..63c539e08 100644 --- a/packages/generational-box/README.md +++ b/packages/generational-box/README.md @@ -31,4 +31,4 @@ let store = Store::default(); ## How it works -Internally \ No newline at end of file +Internally \ No newline at end of file diff --git a/packages/generational-box/src/lib.rs b/packages/generational-box/src/lib.rs index 60bd41419..4be383b4f 100644 --- a/packages/generational-box/src/lib.rs +++ b/packages/generational-box/src/lib.rs @@ -184,7 +184,7 @@ impl GenerationalBox { } /// Try to read the value. Returns None if the value is no longer valid. - pub fn try_read(&self) -> Option> { + pub fn try_read(&self) -> Option> { self.validate() .then(|| { Ref::filter_map(self.raw.data.borrow(), |any| { @@ -196,12 +196,12 @@ impl GenerationalBox { } /// Read the value. Panics if the value is no longer valid. - pub fn read(&self) -> Ref<'_, T> { + pub fn read(&self) -> Ref<'static, T> { self.try_read().unwrap() } /// Try to write the value. Returns None if the value is no longer valid. - pub fn try_write(&self) -> Option> { + pub fn try_write(&self) -> Option> { self.validate() .then(|| { RefMut::filter_map(self.raw.data.borrow_mut(), |any| { @@ -213,7 +213,7 @@ impl GenerationalBox { } /// Write the value. Panics if the value is no longer valid. - pub fn write(&self) -> RefMut<'_, T> { + pub fn write(&self) -> RefMut<'static, T> { self.try_write().unwrap() } 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/lib.rs b/packages/hooks/src/lib.rs index ec2889e55..a5b92a036 100644 --- a/packages/hooks/src/lib.rs +++ b/packages/hooks/src/lib.rs @@ -1,3 +1,6 @@ +#![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(feature = "nightly-features", feature(debug_refcell))] #[macro_export] 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/elements.rs b/packages/html/src/elements.rs index 7004ac1b7..6a0e546fa 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -1107,6 +1107,7 @@ builder_constructors! { formnovalidate: Bool DEFAULT, formtarget: Target DEFAULT, height: isize DEFAULT, + initial_checked: Bool DEFAULT, list: Id DEFAULT, max: String DEFAULT, maxlength: usize DEFAULT, 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/html/src/lib.rs b/packages/html/src/lib.rs index 2fc1baeac..6dd7c42bd 100644 --- a/packages/html/src/lib.rs +++ b/packages/html/src/lib.rs @@ -1,3 +1,6 @@ +#![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")] #![allow(non_snake_case)] //! # Dioxus Namespace for HTML diff --git a/packages/interpreter/src/common.js b/packages/interpreter/src/common.js index 0587d60d4..3745e8c6b 100644 --- a/packages/interpreter/src/common.js +++ b/packages/interpreter/src/common.js @@ -51,6 +51,9 @@ export function setAttributeInner(node, field, value, ns) { case "checked": node.checked = truthy(value); break; + case "initial_checked": + node.defaultChecked = truthy(value); + break; case "selected": node.selected = truthy(value); break; diff --git a/packages/interpreter/src/lib.rs b/packages/interpreter/src/lib.rs index 47093c29c..c540b0d7d 100644 --- a/packages/interpreter/src/lib.rs +++ b/packages/interpreter/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + pub static INTERPRETER_JS: &str = include_str!("./interpreter.js"); pub static COMMON_JS: &str = include_str!("./common.js"); diff --git a/packages/interpreter/src/sledgehammer_bindings.rs b/packages/interpreter/src/sledgehammer_bindings.rs index 23430688e..e2633d024 100644 --- a/packages/interpreter/src/sledgehammer_bindings.rs +++ b/packages/interpreter/src/sledgehammer_bindings.rs @@ -80,6 +80,9 @@ mod js { case "checked": node.checked = truthy(value); break; + case "initial_checked": + node.defaultChecked = truthy(value); + break; case "selected": node.selected = truthy(value); break; diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs index a7370e91c..6a2768fd5 100644 --- a/packages/liveview/src/lib.rs +++ b/packages/liveview/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + pub mod adapters { #[cfg(feature = "warp")] pub mod warp_adapter; diff --git a/packages/mobile/src/lib.rs b/packages/mobile/src/lib.rs index 36940cff7..5cc2c6ae9 100644 --- a/packages/mobile/src/lib.rs +++ b/packages/mobile/src/lib.rs @@ -1,3 +1,5 @@ #![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")] pub use dioxus_desktop::*; diff --git a/packages/native-core-macro/src/lib.rs b/packages/native-core-macro/src/lib.rs index d122838bd..fdaa12cf5 100644 --- a/packages/native-core-macro/src/lib.rs +++ b/packages/native-core-macro/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + extern crate proc_macro; use std::collections::HashSet; diff --git a/packages/native-core/src/lib.rs b/packages/native-core/src/lib.rs index c5ad38341..dd36990a7 100644 --- a/packages/native-core/src/lib.rs +++ b/packages/native-core/src/lib.rs @@ -1,4 +1,6 @@ #![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")] #![warn(missing_docs)] use std::any::Any; diff --git a/packages/rink/src/lib.rs b/packages/rink/src/lib.rs index 81ab45a85..2eba1b98a 100644 --- a/packages/rink/src/lib.rs +++ b/packages/rink/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + use crate::focus::Focus; use anyhow::Result; use crossterm::{ diff --git a/packages/router-macro/src/lib.rs b/packages/router-macro/src/lib.rs index b1ff7b0fe..8844c6a35 100644 --- a/packages/router-macro/src/lib.rs +++ b/packages/router-macro/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + extern crate proc_macro; use layout::Layout; 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/router/src/lib.rs b/packages/router/src/lib.rs index a92394513..e871dc6c9 100644 --- a/packages/router/src/lib.rs +++ b/packages/router/src/lib.rs @@ -1,4 +1,6 @@ #![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")] // cannot use forbid, because props derive macro generates #[allow(missing_docs)] #![deny(missing_docs)] #![allow(non_snake_case)] diff --git a/packages/rsx-rosetta/src/lib.rs b/packages/rsx-rosetta/src/lib.rs index 2ceb5f038..3c11f3a90 100644 --- a/packages/rsx-rosetta/src/lib.rs +++ b/packages/rsx-rosetta/src/lib.rs @@ -1,3 +1,7 @@ +#![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")] + use convert_case::{Case, Casing}; use dioxus_rsx::{ BodyNode, CallBody, Component, Element, ElementAttr, ElementAttrNamed, ElementName, IfmtInput, diff --git a/packages/rsx/src/lib.rs b/packages/rsx/src/lib.rs index f52ecad0e..bdf32b272 100644 --- a/packages/rsx/src/lib.rs +++ b/packages/rsx/src/lib.rs @@ -1,3 +1,6 @@ +#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")] +#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")] + //! Parse the root tokens in the rsx!{} macro //! ========================================= //! diff --git a/packages/server-macro/src/lib.rs b/packages/server-macro/src/lib.rs index 7cdc470d9..5ad9a682b 100644 --- a/packages/server-macro/src/lib.rs +++ b/packages/server-macro/src/lib.rs @@ -1,3 +1,7 @@ +// TODO: Create README, uncomment this: #![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")] + use convert_case::{Case, Converter}; use proc_macro::TokenStream; use proc_macro2::Literal; @@ -105,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/lib.rs b/packages/signals/src/lib.rs index 72cba6a2d..c80dab131 100644 --- a/packages/signals/src/lib.rs +++ b/packages/signals/src/lib.rs @@ -1,4 +1,6 @@ #![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")] #![warn(missing_docs)] mod rt; diff --git a/packages/signals/src/rt.rs b/packages/signals/src/rt.rs index 113fe9b30..0f89a3fe6 100644 --- a/packages/signals/src/rt.rs +++ b/packages/signals/src/rt.rs @@ -1,5 +1,7 @@ use std::cell::{Ref, RefMut}; +use std::mem::MaybeUninit; +use std::ops::Deref; use std::rc::Rc; use dioxus_core::prelude::*; @@ -120,17 +122,17 @@ impl CopyValue { } /// Read the value. If the value has been dropped, this will panic. - pub fn read(&self) -> Ref<'_, T> { + pub fn read(&self) -> Ref<'static, T> { self.value.read() } /// Try to write the value. If the value has been dropped, this will return None. - pub fn try_write(&self) -> Option> { + pub fn try_write(&self) -> Option> { self.value.try_write() } /// Write the value. If the value has been dropped, this will panic. - pub fn write(&self) -> RefMut<'_, T> { + pub fn write(&self) -> RefMut<'static, T> { self.value.write() } @@ -164,3 +166,36 @@ impl PartialEq for CopyValue { self.value.ptr_eq(&other.value) } } + +impl Deref for CopyValue { + type Target = dyn Fn() -> Ref<'static, T>; + + fn deref(&self) -> &Self::Target { + // https://github.com/dtolnay/case-studies/tree/master/callable-types + + // First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit). + let uninit_callable = MaybeUninit::::uninit(); + // Then move that value into the closure. We assume that the closure now has a in memory layout of Self. + let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() }); + + // Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure. + let size_of_closure = std::mem::size_of_val(&uninit_closure); + assert_eq!(size_of_closure, std::mem::size_of::()); + + // Then cast the lifetime of the closure to the lifetime of &self. + fn cast_lifetime<'a, T>(_a: &T, b: &'a T) -> &'a T { + b + } + let reference_to_closure = cast_lifetime( + { + // The real closure that we will never use. + &uninit_closure + }, + // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. + unsafe { std::mem::transmute(self) }, + ); + + // Cast the closure to a trait object. + reference_to_closure as &Self::Target + } +} 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 567534ec5..921aa356e 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -1,6 +1,7 @@ use crate::SignalMap; use std::{ cell::{Ref, RefCell, RefMut}, + mem::MaybeUninit, ops::{Deref, DerefMut}, rc::Rc, sync::Arc, @@ -44,6 +45,7 @@ use crate::{CopyValue, Effect}; /// } /// } /// ``` +#[must_use] pub fn use_signal(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal { *cx.use_hook(|| Signal::new(f())) } @@ -274,6 +276,39 @@ impl PartialEq for Signal { } } +impl Deref for Signal { + type Target = dyn Fn() -> Ref<'static, T>; + + fn deref(&self) -> &Self::Target { + // https://github.com/dtolnay/case-studies/tree/master/callable-types + + // First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit). + let uninit_callable = MaybeUninit::::uninit(); + // Then move that value into the closure. We assume that the closure now has a in memory layout of Self. + let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() }); + + // Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure. + let size_of_closure = std::mem::size_of_val(&uninit_closure); + assert_eq!(size_of_closure, std::mem::size_of::()); + + // Then cast the lifetime of the closure to the lifetime of &self. + fn cast_lifetime<'a, T>(_a: &T, b: &'a T) -> &'a T { + b + } + let reference_to_closure = cast_lifetime( + { + // The real closure that we will never use. + &uninit_closure + }, + // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. + unsafe { std::mem::transmute(self) }, + ); + + // Cast the closure to a trait object. + reference_to_closure as &Self::Target + } +} + struct SignalSubscriberDrop { signal: Signal, } @@ -311,7 +346,7 @@ impl<'a, T: 'static, I: 'static> Write<'a, T, I> { } } -impl<'a, T: 'static> Deref for Write<'a, T> { +impl<'a, T: 'static, I: 'static> Deref for Write<'a, T, I> { type Target = T; fn deref(&self) -> &Self::Target { @@ -319,7 +354,7 @@ impl<'a, T: 'static> Deref for Write<'a, T> { } } -impl DerefMut for Write<'_, T> { +impl DerefMut for Write<'_, T, I> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.write } @@ -364,3 +399,36 @@ impl PartialEq for ReadOnlySignal { self.inner == other.inner } } + +impl Deref for ReadOnlySignal { + type Target = dyn Fn() -> Ref<'static, T>; + + fn deref(&self) -> &Self::Target { + // https://github.com/dtolnay/case-studies/tree/master/callable-types + + // First we create a closure that captures something with the Same in memory layout as Self (MaybeUninit). + let uninit_callable = MaybeUninit::::uninit(); + // Then move that value into the closure. We assume that the closure now has a in memory layout of Self. + let uninit_closure = move || Self::read(unsafe { &*uninit_callable.as_ptr() }); + + // Check that the size of the closure is the same as the size of Self in case the compiler changed the layout of the closure. + let size_of_closure = std::mem::size_of_val(&uninit_closure); + assert_eq!(size_of_closure, std::mem::size_of::()); + + // Then cast the lifetime of the closure to the lifetime of &self. + fn cast_lifetime<'a, T>(_a: &T, b: &'a T) -> &'a T { + b + } + let reference_to_closure = cast_lifetime( + { + // The real closure that we will never use. + &uninit_closure + }, + // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. + unsafe { std::mem::transmute(self) }, + ); + + // Cast the closure to a trait object. + reference_to_closure as &Self::Target + } +} diff --git a/packages/signals/tests/create.rs b/packages/signals/tests/create.rs index 57d8325af..ecda2f376 100644 --- a/packages/signals/tests/create.rs +++ b/packages/signals/tests/create.rs @@ -29,6 +29,30 @@ fn create_signals_global() { } } +#[test] +fn deref_signal() { + let mut dom = VirtualDom::new(|cx| { + render! { + for _ in 0..10 { + Child {} + } + } + }); + + fn Child(cx: Scope) -> Element { + let signal = Signal::new("hello world".to_string()); + + // You can call signals like functions to get a Ref of their value. + assert_eq!(&*signal(), "hello world"); + + render! { + "hello world" + } + } + + let _edits = dom.rebuild().santize(); +} + #[test] fn drop_signals() { let mut dom = VirtualDom::new(|cx| { diff --git a/packages/ssr/src/lib.rs b/packages/ssr/src/lib.rs index 45e3f59ea..6794d1f14 100644 --- a/packages/ssr/src/lib.rs +++ b/packages/ssr/src/lib.rs @@ -1,4 +1,6 @@ #![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")] mod cache; pub mod config; diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 60f84de37..944ed3150 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -1,3 +1,5 @@ +#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")] +#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")] #![deny(missing_docs)] //! Dioxus WebSys