sycamore/
lib.rs

1//! # Sycamore API Documentation
2//!
3//! Sycamore is a **reactive** library for creating web apps in **Rust** and **WebAssembly**.
4//!
5//! This is the API docs for sycamore. If you are looking for the usage docs, checkout the
6//! [Sycamore Book](https://sycamore-rs.netlify.app/docs/getting_started/installation).
7//!
8//! ## Feature Flags
9//!
10//! - `hydrate` - Enables hydration support in DOM nodes. By default, hydration is disabled to
11//!   reduce binary size.
12//!
13//! - `serde` - Enables serializing and deserializing `Signal`s and other wrapper types using
14//!   `serde`.
15//!
16//! - `suspense` - Enables wrappers around `wasm-bindgen-futures` to make it easier to extend a
17//!   reactive scope into an `async` function.
18//!
19//! - `nightly` - Enables nightly-only features. This makes it slightly more ergonomic to use
20//!   signals.
21//!
22//! - `wasm-bindgen-interning` (_default_) - Enables interning for `wasm-bindgen` strings. This
23//!   improves performance at a slight cost in binary size. If you want to minimize the size of the
24//!   result `.wasm` binary, you might want to disable this.
25//!
26//! - `web` (_default_) - Enables the web backend for Sycamore. This feature is enabled by most of
27//!   the other features so you should rarely need to enable it manually.
28
29#![warn(clippy::clone_on_ref_ptr)]
30#![warn(clippy::rc_buffer)]
31#![warn(clippy::semicolon_if_nothing_returned)]
32#![warn(missing_docs)]
33#![warn(rust_2018_idioms)]
34#![deny(clippy::trait_duplication_in_bounds)]
35#![deny(clippy::type_repetition_in_bounds)]
36#![deny(missing_debug_implementations)]
37
38// Alias self to `sycamore` to make it possible to use proc-macros within the `sycamore` crate.
39#[allow(unused_extern_crates)] // False positive
40extern crate self as sycamore;
41
42pub mod easing;
43pub mod motion;
44
45/* Re-export of the sycamore-macro crate */
46pub use sycamore_macro::*;
47
48/// Reactive primitives for Sycamore.
49///
50/// Re-export of the [`sycamore_reactive`] crate.
51pub mod reactive {
52    pub use sycamore_reactive::*;
53}
54
55/// Web support for Sycamore.
56///
57/// Re-export of the [`sycamore_web`] crate.
58pub mod web {
59    pub use sycamore_web::*;
60}
61
62/// Utilities for working with async.
63///
64/// Re-export of the [`sycamore_futures`] crate.
65#[cfg(feature = "suspense")]
66pub mod futures {
67    pub use sycamore_futures::*;
68}
69
70#[cfg(feature = "hydrate")]
71pub use sycamore_web::{hydrate, hydrate_in_scope, hydrate_to};
72pub use sycamore_web::{
73    render, render_in_scope, render_to, render_to_string, render_to_string_in_scope,
74};
75#[cfg(feature = "suspense")]
76pub use sycamore_web::{render_to_string_await_suspense, render_to_string_stream};
77
78/// The Sycamore prelude.
79///
80/// In most cases, it is idiomatic to use a glob import (aka wildcard import) at the beginning of
81/// your Rust source file.
82///
83/// ```rust
84/// use sycamore::prelude::*;
85/// ```
86pub mod prelude {
87    pub use sycamore_core::{Component, Props};
88    #[cfg(feature = "web")]
89    pub use sycamore_macro::*;
90    #[cfg(feature = "web")]
91    pub use sycamore_web::tags::html_attributes::*;
92    #[cfg(feature = "web")]
93    pub use sycamore_web::tags::svg_attributes::*;
94    #[cfg(feature = "web")]
95    pub use sycamore_web::{
96        console_dbg, console_log, create_node_ref, document, is_not_ssr, is_ssr, on_mount, window,
97        Attributes, Children, GlobalAttributes, GlobalProps, HtmlGlobalAttributes, Indexed, Keyed,
98        NodeRef, SvgGlobalAttributes, View,
99    };
100
101    pub use crate::reactive::*;
102}
103
104/// Re-exports for use by `sycamore-macro`. Not intended for use by end-users.
105#[doc(hidden)]
106pub mod rt {
107    pub use sycamore_core::{component_scope, element_like_component_builder, Component, Props};
108    #[cfg(feature = "suspense")]
109    pub use sycamore_futures::*;
110    pub use sycamore_macro::*;
111    pub use sycamore_reactive::*;
112    #[cfg(feature = "web")]
113    pub use sycamore_web::*;
114    #[cfg(feature = "web")]
115    pub use web_sys::Event;
116}