Crate seed

source · []
Expand description

Visit the website

See the github Readme for details

Counter Example

use seed::{prelude::*, *};

// `init` describes what should happen when your app started.
fn init(_: Url, _: &mut impl Orders<Msg>) -> Model {
    Model { counter: 0 }

// `Model` describes our app state.
struct Model { counter: i32 }

// `Msg` describes the different events you can modify state with.
enum Msg {

// `update` describes how to handle each `Msg`.
fn update(msg: Msg, model: &mut Model, _: &mut impl Orders<Msg>) {
    match msg {
        Msg::Increment => model.counter += 1,

// `view` describes what to display.
fn view(model: &Model) -> Node<Msg> {
        "This is a counter: ",
            ev(Ev::Click, |_| Msg::Increment),

pub fn start() {
    // Mount the `app` to the element with the `id` "app".
    App::start("app", init, update, view);


pub use crate::app::App;
pub use crate::browser::dom::cast::to_drag_event;
pub use crate::browser::dom::cast::to_html_el;
pub use crate::browser::dom::cast::to_input;
pub use crate::browser::dom::cast::to_keyboard_event;
pub use crate::browser::dom::cast::to_mouse_event;
pub use crate::browser::dom::cast::to_select;
pub use crate::browser::dom::cast::to_textarea;
pub use crate::browser::dom::cast::to_touch_event;
pub use crate::browser::dom::cast::to_wheel_event;
pub use crate::browser::fetch;
pub use crate::browser::url::Url;
pub use crate::browser::util;
pub use crate::browser::util::body;
pub use crate::browser::util::canvas;
pub use crate::browser::util::canvas_context_2d;
pub use crate::browser::util::cookies;
pub use crate::browser::util::error;
pub use crate::browser::util::html_document;
pub use crate::browser::util::log;
pub use crate::virtual_dom::Attrs;
pub use crate::virtual_dom::EventHandler;
pub use crate::virtual_dom::Style;
pub use futures;


Asynchronous values.

Introduce El and Tag into the global namespace for convenience (El will be repeated often in the output type of components), and UpdateEl, which is required for element-creation macros, input event constructors, and the History struct. Expose the wasm_bindgen prelude.

This file exports helper macros for element creation, populated by a higher-level macro, and macros for creating the parts of elements. (attrs, style, events)


Add classes into the element.

IF!(predicate => expression) -> Option<expression value>

Provide a shortcut for creating attributes.


Convenience macro. Ideal when there are multiple classes, and no other attrs.

Similar to log!

Convenience macro, for brevity.

A key-value pairs, where the keys and values must implement ToString.

A convenience function for logging to the web browser’s console. We use a macro to supplement the log function to allow multiple inputs.

Converts items to Vec<Node<Ms> and returns flattened Vec<Node<Ms>.

Create struct Urls. It’s useful especially for building Urls in nested modules.

Provide a shortcut for creating styles.

Allows to write nested macros.


A Rust Future backed by a JavaScript Promise.


An extension trait for Futures that provides a variety of convenient adapters.

Adapters specific to Result-returning futures


Convenience function to access the web_sys DOM document.

Create an element flagged in a way that it will not be rendered. Useful in ternary operations.

Convenience function to access the web_sys history.


A high-level wrapper for web_sys::window.set_interval_with_callback_and_timeout_and_arguments_0:

Runs a Rust Future on the current thread.

Convenience function to avoid repeating expect logic.