Skip to main content

Module debug

Module debug 

Source
Expand description

The debug bridge: collectors that describe a part of the running application, snapshot it as JSON and act on it. Every call returns a Feedback block, success or not, saying what happened and whether anything changed; actions that change something are flagged mutates. Agents, test tools and debug pages use the same bridge.

Every action also says whether agents may call it (agent): by default those that only read, and none that writes unless it says so (FnCollector::agent) or the application offers it (DebugBridge::offer_to_agents). DebugBridge::call is the agent’s (Origin::Agent("debug-bridge")) and refuses the others; DebugBridge::call_as names who calls, and only the user may call an action not offered to agents. The bridge’s BridgeMode holds anyone but the user: on, read-only (only calls that do not mutate) or off.

use egui_pop_core::debug::{DebugBridge, FnCollector};
use egui_pop_model::commands::Origin;
use serde_json::json;

let ctx = egui::Context::default();
let mut bridge = DebugBridge::with_core_collectors();
bridge.register(
    FnCollector::new("clock", "A clock.")
        .snapshot(|_| json!({ "ticks": 3 }))
        .action("tick", "Advances the clock.", true, |_, _| Ok(json!({ "ticks": 4 })))
        .action("read", "Reads the clock.", false, |_, _| Ok(json!({ "ticks": 3 }))),
).unwrap();
// It writes: not for agents, the user may.
let f = bridge.call(&ctx, "clock", "tick", &json!(null));
assert!(!f.ok && f.message.contains("not offered to agents"), "{}", f.message);
let f = bridge.call_as(&ctx, "clock", "tick", &json!(null), &Origin::User);
assert!(f.ok && f.mutates);
// It reads: agents may.
assert!(bridge.call(&ctx, "clock", "read", &json!(null)).ok);
let f = bridge.call(&ctx, "clock", "explode", &json!(null));
assert!(!f.ok);
assert!(f.message.contains("tick"), "it lists the actions: {}", f.message);

Structs§

ActionSpec
An action a collector offers.
DebugBridge
The collectors, by name.
Feedback
What a call did. Always returned, success or not.
FnCollector
A collector made of closures.
Schemas
The JSON Schemas of an action: of its arguments and of its result, when its author gives them. describe lists them; the example of the arguments (ActionSpec::args) stays beside them.

Enums§

BridgeMode
What the bridge lets anyone but the user do (AppBuilder::debug_bridge): the user’s calls (devtools, a debug page) are never refused by it.

Constants§

AGENT
The identity of the bridge’s calls: Origin::Agent("debug-bridge").
KEPT
How many feedback blocks the bridge keeps.
PROTOCOL
The version of the capability protocol: what DebugBridge::capabilities lists and how. It changes only when a field changes meaning; adding capabilities or fields keeps it.

Traits§

Collector
A part of the application, seen by the bridge.

Functions§

agent
The origin of the bridge’s calls.
core_collectors
The collectors of this crate.
is_schema
Whether a command’s or an action’s free description of its arguments is a JSON Schema rather than an example: an object of schema keywords naming a type, $schema, properties or a combinator.
store_collector
A collector over a value store: paths, values, gestures; get, set, undo.