pub struct Loader { /* private fields */ }Expand description
Cheap cloneable loader handle.
Implementations§
Source§impl Loader
impl Loader
Sourcepub fn open(root: &Context, config: LoaderConfig) -> Result<Loader>
pub fn open(root: &Context, config: LoaderConfig) -> Result<Loader>
Open (creating if needed) the entry file, load the tree, and start every enabled entry.
Entries that fail to resolve or start do not abort the open; the
error is recorded and retrievable via Loader::last_error, and the
offending entry simply has no (or a failed) fiber.
Sourcepub fn file(&self) -> &LoaderFile
pub fn file(&self) -> &LoaderFile
The entry config file.
Sourcepub fn registry(&self) -> PluginRegistry
pub fn registry(&self) -> PluginRegistry
The plugin registry (a clone of the current state); populate it via
LoaderConfig::with_registry before open, or
Loader::register_plugin later.
Sourcepub fn register_plugin<P: Plugin>(&self, plugin: P)
pub fn register_plugin<P: Plugin>(&self, plugin: P)
Register one plugin instance by its own name; picked up by the next reload (or immediately for not-yet-started entries).
Sourcepub fn register<F>(&self, name: impl Into<String>, factory: F)
pub fn register<F>(&self, name: impl Into<String>, factory: F)
Register a handle factory under a name.
Sourcepub fn last_error(&self) -> Option<String>
pub fn last_error(&self) -> Option<String>
The last background error recorded by the loader, if any.
Sourcepub fn set_write_debounce(&self, delay: Option<Duration>)
pub fn set_write_debounce(&self, delay: Option<Duration>)
Set (or clear, with None) the debounce window for coalesced
config writes.
Sourcepub fn locate(&self, fiber: &Fiber) -> Option<Entry>
pub fn locate(&self, fiber: &Fiber) -> Option<Entry>
The entry whose fiber is fiber, if the loader started it.
Sourcepub fn reload(&self) -> Result<TreeDiff>
pub fn reload(&self) -> Result<TreeDiff>
Re-read the entry file and apply the difference to the fibers.
Created entries start (parents first), removed subtrees stop, moved
entries restart under their new parent, redefined entries (plugin
name, inject declaration, or enabled flag changed) stop and start
with their new options, and updated entries are patched in place —
their config-only change never restarts the fiber. A patch the
plugin rejects leaves the fiber on its current config and is
retried by the next reload. Patches are never written back to the
file; only newly generated ids are persisted afterwards. The whole
reconcile runs under the loader’s operation lock, serialized
against update_config and
dispose.
Sourcepub fn update(&self, document: Document) -> Result<TreeDiff>
pub fn update(&self, document: Document) -> Result<TreeDiff>
Recompose from a caller-supplied document — the in-memory twin of
reload: the same full reconcile (diff → stop →
patch → start) under the same operation lock, but composed from
document instead of any file, and without write-back. A
recomposition is not a file edit (upstream’s internal/update
persists nothing either); ids generated for id-less rows stay in
memory, so those rows restart on every recomposition — the draft is
regenerated anyway.
The document also becomes the loader’s composition source: later
reloads recompose from it instead of re-reading the root file
(import files are still read). This is the core HMR primitive — a
watcher recomposes fresh layers and hands the result to update.
Sourcepub fn update_config(&self, id: &str, config: Node) -> Result<()>
pub fn update_config(&self, id: &str, config: Node) -> Result<()>
Change one entry’s config at runtime: the fiber is updated (and restarted when active) and the new config is persisted to the file.
Sourcepub fn dispose(&self) -> Result<()>
pub fn dispose(&self) -> Result<()>
Stop every entry, stop watching files, and release the loader’s
root-level effects (the status listener and the loader service).
The root context stays usable, and a fresh Loader::open on the
same root works afterwards.