Skip to content

ShabbirHasan1/concoct

 
 

Repository files navigation

Concoct

Crates.io version docs.rs docs CI status

Concoct is a framework for user-interfaces in Rust.

This crate provides a diffing-engine and state management system for any backend. Concoct uses static typing to describe your UI at compile-time to create an efficient tree without allocations. Updates to state re-render your application top-down, starting at the state's parent component.

struct App;

impl ViewBuilder for App {
    fn build(&self) -> impl View {
        let (count, set_high) = use_state(|| 0);
        let set_low = set_high.clone();

        (
            format!("High five count: {}", count),
            html::button("Up high!").on_click(move |_| set_high(count + 1)),
            html::button("Down low!").on_click(move |_| set_low(count - 1)),
        )
    }
}

Components

struct Readme {
    crate_name: String,
    version: String,
}

impl ViewBuilder for Readme {
    fn build(&self) -> impl View {
        let (content, set_content) = use_state(|| None);

        use_effect(&self.crate_name, || {
            let name = self.crate_name.clone();
            let version = self.version.clone();
            spawn_local(async move {
                let readme = api::get_readme(&name, &version).await;
                set_content(Some(readme));
            })
        });

        content
            .map(|content| OneOf2::A(content))
            .unwrap_or_else(|| OneOf2::B("Loading..."))
    }
}

struct App;

impl ViewBuilder for App {
    fn build(&self) -> impl View {
        Readme {
            crate_name: String::from("concoct"),
            version: String::from("1.0"),
        }
    }
}

Installation

The easiest way to get started is using the full feature flag.

cargo add concoct --features full

To see a list of the available features flags that can be enabled, check our docs.

About

A runtime for user-interfaces in Rust.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 99.5%
  • HTML 0.5%