Rust SDK
Files:
sdk/rust/Cargo.tomlsdk/rust/src/lib.rs(crateshire-sdk)shire-plugin initcopies the source assrc/shire_sdk.rsfor a standalone plugin.
The SDK uses two connections: a request connection (write then read the matching
response) and an event connection read by a thread. It depends on
serde_json.
Connect
let mut client = shire_sdk::Client::from_env().expect("connect");
It reads SHIRE_PLUGIN_PIPE, SHIRE_PLUGIN_TOKEN and SHIRE_PLUGIN_ID, opens
both connections and performs the handshake.
Calls
let pos = client.player_position()?;
let scene = client.scene()?;
let entities = client.entities(64)?;
let markers = client.markers(128)?;
client.teleport(1.0, 2.0, 3.0, 0)?;
client.notify("Title", "Body")?;
client.log("message")?;
client.storage_set("key", serde_json::json!({"n": 1}))?;
let value = client.storage_get("key")?;
client.subscribe(&["player.position", "scene.changed"])?;
Errors are Result<_, String> with the Host code/message in the string.
UI
use serde_json::json;
client.set_ui(json!([
{"type": "text", "id": "title", "text": "Hello from Rust"},
{"type": "toggle", "id": "enabled", "label": "Enabled", "value": true},
{"type": "button", "id": "ping", "label": "Ping"}
]))?;
Client::text, section, button, toggle and slider return serde_json::Value
descriptors. set_ui sends the whole layout; update_ui(id, json!({...}))
updates one component.
Events
run() blocks and prints events; for custom handling:
client.subscribe(&["player.position"])?;
while let Some((event, data)) = client.try_event() {
println!("{event}: {data}");
}
For blocking event delivery use client.run(); the event receiver is internal.
The event connection thread only reads; the request connection is never read
concurrently.
Build and manifest
cargo build --release --target-dir out
The manifest:
{
"language": "executable",
"entrypoint": "out/release/plugin.exe",
"permissions": ["notifications.show", "ui.create"]
}
shire-plugin build detects Cargo.toml and builds with
--target-dir out. The SDK is Windows only because the Shire transport is a
Windows named pipe.