Crate concoct

source ·
Expand description

Concoct

Concoct is a runtime for user-interfaces in Rust.

Feature flags

Concoct uses a set of feature flags to reduce the amount of compiled code.

  • full: Enables all features listed below.
  • tokio: Enables interop with the tokio runtime.
use concoct::{Handle, Object, Runtime, Signal, Slot};

#[derive(Default)]
pub struct Counter {
    value: i32,
}

impl Object for Counter {}

impl Signal<i32> for Counter {}

impl Slot<i32> for Counter {
    fn handle(&mut self, cx: Handle<Self>, msg: i32) {
        if self.value != msg {
            self.value = msg;
            cx.emit(msg);
        }
    }
}

#[tokio::main]
async fn main() {
    let rt = Runtime::default();
    let _guard = rt.enter();

    let a = Counter::default().start();
    let b = Counter::default().start();

    a.bind(&b);

    a.send(1);
    a.send(2);

    rt.run().await;

    assert_eq!(a.borrow().value, 2);
    assert_eq!(b.borrow().value, 2);
}

Re-exports

Modules

Structs

  • Handle to a spawned object.
  • Type-erased handle to an object.
  • Handle to an object’s signal for a specific message.
  • Handle to an object’s slot for a specific message.

Traits

  • A reactive object.
  • Signal emitter of messages for an object.
  • Slot handler of messages for an object.