Expand description
§Slung Rust SDK
An abstraction library for interacting with the Slung runtime.
§Quickstart
Add to your rust project’s Cargo.toml:
[dependencies]
slung = "0.1.0"And then at the top of your module:
use slung::prelude::*;§Example
Here’s a basic anomaly detection example:
use slung::prelude::*;
#[main]
fn main() -> Result<()> {
// Subscribe to live stream updates.
let handle = query_live("AVG:temp:[sensor=1]")?;
poll_handle(handle, on_event, 100.0)?;
Ok(())
}
fn on_event(event: Event, alert_threshold: f64) -> Result<()> {
if event.value > alert_threshold {
println!("event timestamp={} value={}", event.timestamp, event.value);
for producer in event.producers {
writeback_ws(producer, "ALERT: threshold exceeded")?;
}
}
Ok(())
}§Query Syntax
OP:SERIES:[TAGS]:[RANGE]
- RANGE is optional
- OP: AVG, MIN, MAX, SUM, COUNT
- TAGS: AND, OR, NOT
- RANGE:
[start_time,end_time]. Timestamps in microseconds. Also supports sec, min, hour, day, week (short & plural forms apply).
§License
Unlike the root project, this SDK is licensed under the MIT License - see the LICENSE file for details.
Modules§
- prelude
- Common imports for workflow handlers.
Structs§
Enums§
- Poll
State - Polled aggregate state variants.
- Writeback
Method - HTTP method mapping expected by the host writeback API.
Functions§
- free_
handle - Free a live query handle on the host.
- poll_
handle - Poll a live query forever and invoke
callbackfor each received event. - poll_
handle_ state - Poll a live query once and decode aggregate state if available.
- query_
history - Execute a historical aggregation query and return the aggregate value.
- query_
live - Register a live query and return its host handle.
- unix_
micros - Return the current Unix epoch timestamp in microseconds.
- write_
event - Write a new event to the host.
- writeback_
http - Send an HTTP writeback request through the host.
- writeback_
ws - Write back text data to a websocket producer destination.
Type Aliases§
- Query
Handle - Opaque handle returned by live-query registration.