tincan 0.3.0

A lightweight reactive state management library for Rust.
Documentation
//! Basic example demonstrating signal creation and updates
//!
//! Run with: cargo run --example basic

use tincan::Scope;

fn main() {
    println!("=== Basic Tincan Example ===\n");

    // Create a reactive scope
    let cx = Scope::new();

    // Create signals (reactive state)
    let count = cx.signal(0);
    println!("Initial count: {}", count.get());

    // Update the signal
    count.set(5);
    println!("After set(5): {}", count.get());

    // Update using a function
    count.update(|n| *n += 10);
    println!("After update(+10): {}", count.get());

    // Read without cloning
    let doubled = count.with(|n| n * 2);
    println!("Doubled value: {}", doubled);

    // Create a string signal
    let name = cx.signal(String::from("Alice"));
    println!("\nName: {}", name.get());

    name.set(String::from("Bob"));
    println!("Updated name: {}", name.get());

    // Working with complex types
    let items = cx.signal(vec![1, 2, 3]);
    println!("\nItems: {:?}", items.get());

    items.update(|v| v.push(4));
    println!("After push: {:?}", items.get());

    let sum = items.with(|v| v.iter().sum::<i32>());
    println!("Sum of items: {}", sum);
}