Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Быстрый старт

Самый простой способ создать проект — установить CLI и выбрать шаблон:

cargo install light-fw-cli
light init my-app --template counter
cd my-app
cargo run

Доступны три showcase-шаблона: counter, todo и calculator. Их исходники лежат в каталоге examples/.

Для пустого проекта без шаблона:

light init my-app

Дополнительные компоненты подключаются флагом --with:

light init my-app --with form --with validation

Вручную

Если CLI не нужен, создайте проект обычным способом.

Cargo.toml:

[package]
name = "my-app"
version = "0.1.0"
edition = "2024"

[dependencies]
light = { git = "https://github.com/gifoff/light" }

src/main.rs:

use light::prelude::*;

#[template("templates/app.html")]
#[proxy]
struct App {
    #[default("Мир".to_owned())]
    name: String,
}

impl App {
    fn greet(&self) {
        self.set_name(format!("Привет, {}!", self.name()));
    }
}

fn main() -> light::Result<()> {
    light::run(App::new())
}

templates/app.html:

<window title="My App" width="480" height="320">
    <div direction="vertical" padding="16">
        <h1>Привет, {{ name }}!</h1>
        <button @click="greet">Поздороваться</button>
    </div>
</window>

Запуск:

cargo run

Дальше