docs

std::reload

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

hot reload under nabi dev: where changes apply, code that runs around them, and state that lives through them.

nabi dev swaps in each package you edit while the program runs. Calls reach the new code at once; a change to a type's fields applies at a moment when no running frame uses the type, usually point(). Outside nabi dev everything here does nothing.

nabi
fn main() {
    let state = new_state();
    loop {
        step(state);
        reload::point();
    }
}

// `main` never names `World` itself, so a change to it can apply.
fn new_state() -> reload::State<World> { reload::State::new(World::new()) }

Structs

ReloadSource

pub struct Reload

One applied change, as the hooks see it.

  • pub package: str§

    Source

    The package that changed.

  • pub version: u64§

    Source

    Its new version (counted by nabi dev).

  • pub functions: List<str>§

    Source

    The functions whose code changed, as game::spawn_wave.

  • pub types: List<str>§

    Source

    The types whose fields changed, as game::Enemy.

StateSource

pub struct State<T>

A value kept across reloads. It lives in its own box, which a change to T's fields rewrites in place or moves; copies of a State share it. Keep the state of main's loop in one: a local of type T there would hold the change back.

  • pub fn new(v: T) -> State<T>§

    Source

    A state holding v.

  • pub fn get(self) -> T§

    Source

    A copy of the value.

  • pub fn set(self, v: T)§

    Source

    Store v.

  • pub fn update(self, f: fn(T) -> T)§

    Source

    Store f of the value.

Functions

activeSource

pub fn active() -> bool

Running under nabi dev.

pointSource

pub fn point()

Apply a change that is ready, here. Call it where no local holds a value of a type you may edit (the top of a frame loop); it does nothing when no change waits or outside nabi dev.

on_reloadSource

pub fn on_reload(name: str, f: fn(Reload) + Send + Sync)

Run f after each change applies, on the thread in point(). A hook registered again under the same name replaces the old one.

before_reloadSource

pub fn before_reload(name: str, f: fn(Reload) + Send + Sync)

Run f before each change applies, on the thread in point(). While such a hook is registered, every change waits for point().

host_mainSource

pub fn host_main()

The whole main of the program nabi dev runs: connect to nabi dev, load the packages' first versions (NABI_DEV_PLUGINS, one path a line, dependencies first) and call NABI_DEV_MAIN of the last one.