dioxus_core/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
3#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
4#![warn(missing_docs)]
5
6mod any_props;
7mod arena;
8mod diff;
9mod effect;
10mod error_boundary;
11mod events;
12mod fragment;
13mod generational_box;
14mod global_context;
15mod launch;
16mod mutations;
17mod nodes;
18mod properties;
19mod reactive_context;
20mod render_error;
21mod root_wrapper;
22mod runtime;
23mod scheduler;
24mod scope_arena;
25mod scope_context;
26mod scopes;
27mod suspense;
28mod tasks;
29mod virtual_dom;
30
31mod hotreload_utils;
32
33/// Items exported from this module are used in macros and should not be used directly.
34#[doc(hidden)]
35pub mod internal {
36    #[doc(hidden)]
37    pub use crate::hotreload_utils::{
38        DynamicLiteralPool, DynamicValuePool, FmtSegment, FmtedSegments, HotReloadAttributeValue,
39        HotReloadDynamicAttribute, HotReloadDynamicNode, HotReloadLiteral,
40        HotReloadTemplateWithLocation, HotReloadedTemplate, HotreloadedLiteral, NamedAttribute,
41        TemplateGlobalKey,
42    };
43
44    #[allow(non_snake_case)]
45    #[doc(hidden)]
46    pub fn Err<T, E>(e: E) -> Result<T, E> {
47        std::result::Result::Err(e)
48    }
49
50    pub use anyhow::__anyhow;
51
52    #[doc(hidden)]
53    pub use generational_box;
54}
55
56pub(crate) mod innerlude {
57    pub(crate) use crate::any_props::*;
58    pub use crate::arena::*;
59    pub(crate) use crate::effect::*;
60    pub use crate::error_boundary::*;
61    pub use crate::events::*;
62    pub use crate::fragment::*;
63    pub use crate::generational_box::*;
64    pub use crate::global_context::*;
65    pub use crate::launch::*;
66    pub use crate::mutations::*;
67    pub use crate::nodes::*;
68    pub use crate::properties::*;
69    pub use crate::reactive_context::*;
70    pub use crate::render_error::*;
71    pub use crate::runtime::{Runtime, RuntimeGuard};
72    pub use crate::scheduler::*;
73    pub use crate::scopes::*;
74    pub use crate::suspense::*;
75    pub use crate::tasks::*;
76    pub use crate::virtual_dom::*;
77
78    pub use anyhow::anyhow;
79    pub use anyhow::Context as AnyhowContext;
80    // pub use anyhow::Error as AnyhowError;
81    // pub type Error = CapturedError;
82
83    /// A result type with a default error of [`CapturedError`].
84    pub type Result<T, E = CapturedError> = std::result::Result<T, E>;
85
86    /// An [`Element`] is a possibly-none [`VNode`] created by calling `render` on [`ScopeId`] or [`ScopeState`].
87    ///
88    /// An Errored [`Element`] will propagate the error to the nearest error boundary.
89    pub type Element = std::result::Result<VNode, RenderError>;
90
91    /// A [`Component`] is a function that takes [`Properties`] and returns an [`Element`].
92    pub type Component<P = ()> = fn(P) -> Element;
93}
94
95pub use crate::innerlude::{
96    anyhow, consume_context, consume_context_from_scope, current_owner, current_scope_id,
97    fc_to_builder, generation, has_context, needs_update, needs_update_any, parent_scope,
98    provide_context, provide_create_error_boundary, provide_root_context, queue_effect,
99    remove_future, schedule_update, schedule_update_any, spawn, spawn_forever, spawn_isomorphic,
100    suspend, throw_error, try_consume_context, use_after_render, use_before_render, use_drop,
101    use_hook, use_hook_with_cleanup, with_owner, AnyValue, AnyhowContext, Attribute,
102    AttributeValue, Callback, CapturedError, Component, ComponentFunction, DynamicNode, Element,
103    ElementId, ErrorBoundary, ErrorContext, Event, EventHandler, Fragment, HasAttributes,
104    IntoAttributeValue, IntoDynNode, LaunchConfig, ListenerCallback, MarkerWrapper, Mutation,
105    Mutations, NoOpMutations, OptionStringFromMarker, Properties, ReactiveContext, RenderError,
106    Result, Runtime, RuntimeGuard, ScopeId, ScopeState, SpawnIfAsync, SubscriberList, Subscribers,
107    SuperFrom, SuperInto, SuspendedFuture, SuspenseBoundary, SuspenseBoundaryProps,
108    SuspenseContext, Task, Template, TemplateAttribute, TemplateNode, VComponent, VNode,
109    VNodeInner, VPlaceholder, VText, VirtualDom, WriteMutations,
110};
111
112/// Equivalent to `Ok::<_, dioxus::CapturedError>(value)`.
113///
114/// This simplifies creation of an `dioxus::Result` in places where type
115/// inference cannot deduce the `E` type of the result &mdash; without needing
116/// to write`Ok::<_, dioxus::CapturedError>(value)`.
117///
118/// One might think that `dioxus::Result::Ok(value)` would work in such cases
119/// but it does not.
120///
121/// ```console
122/// error[E0282]: type annotations needed for `std::result::Result<i32, E>`
123///   --> src/main.rs:11:13
124///    |
125/// 11 |     let _ = dioxus::Result::Ok(1);
126///    |         -   ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result`
127///    |         |
128///    |         consider giving this pattern the explicit type `std::result::Result<i32, E>`, where the type parameter `E` is specified
129/// ```
130#[allow(non_snake_case)]
131pub fn Ok<T>(value: T) -> Result<T, CapturedError> {
132    Result::Ok(value)
133}
134
135pub use const_format;