pub struct WeftBehavior { /* private fields */ }Expand description
A loaded, verified Weft behavior: the module, its persistent state value, and the fuel ceiling (static bound + contract headroom).
Implementations§
Source§impl WeftBehavior
impl WeftBehavior
Sourcepub fn from_json(text: &str) -> Result<Self, String>
pub fn from_json(text: &str) -> Result<Self, String>
Parse + verify a serialized module (the weft asset’s JSON form).
Verification here is the trust boundary — nothing unverified evaluates.
Sourcepub fn from_package_json(text: &str, export: &str) -> Result<Self, String>
pub fn from_package_json(text: &str, export: &str) -> Result<Self, String>
Load a behavior from a package (.weftpack.json) by export petname
— the weft-use path: verify the package, link the export’s closure
into a module, then the usual entry checks. One published export, one
line of markup, a running behavior.
Sourcepub fn effects(&self) -> Vec<EffectKind>
pub fn effects(&self) -> Vec<EffectKind>
The effects this behavior may request (its verified row) — for HUD / permission surfaces.
Sourcepub fn on_interact(&mut self, name: &str, slug: Option<&str>) -> Vec<Action>
pub fn on_interact(&mut self, name: &str, slug: Option<&str>) -> Vec<Action>
Dispatch one interact event. State persists across calls; failures (fuel, contract) degrade to no actions — the world keeps rendering.
Sourcepub fn on_tick(&mut self, dt_ms: i64) -> Vec<Action>
pub fn on_tick(&mut self, dt_ms: i64) -> Vec<Action>
Dispatch one tick. The event record offers kind: "tick" and dt_ms
(the browser throttles cadence); a behavior’s event type picks the
fields it wants, same total projection as interact. This is what makes
a world behave rather than only react — native code with a heartbeat,
still fuel-metered every beat.