Skip to main content

Clasp

Struct Clasp 

Source
pub struct Clasp { /* private fields */ }
Expand description

A Clasp client

Implementations§

Source§

impl Clasp

Source

pub fn new( url: &str, name: String, features: Vec<String>, token: Option<String>, reconnect: bool, reconnect_interval_ms: u64, ) -> Self

Create a new client (use builder for more options)

Source

pub fn builder(url: &str) -> ClaspBuilder

Create a builder

Source

pub async fn connect_to(url: &str) -> Result<Self>

Connect to server (convenience method)

Source

pub fn start_reconnect_loop(self: &Arc<Self>)

Start the reconnect loop (call after initial connect)

Source

pub fn is_connected(&self) -> bool

Check if connected

Source

pub fn session_id(&self) -> Option<String>

Get session ID

Source

pub fn time(&self) -> u64

Get current server time (microseconds)

Source

pub async fn subscribe<F>(&self, pattern: &str, callback: F) -> Result<u32>
where F: Fn(Value, &str) + Send + Sync + 'static,

Subscribe to an address pattern

Source

pub async fn on<F>(&self, pattern: &str, callback: F) -> Result<u32>
where F: Fn(Value, &str) + Send + Sync + 'static,

Shorthand for subscribe

Source

pub async fn unsubscribe(&self, id: u32) -> Result<()>

Unsubscribe

Source

pub async fn set(&self, address: &str, value: impl Into<Value>) -> Result<()>

Set a parameter value

Source

pub async fn set_locked( &self, address: &str, value: impl Into<Value>, ) -> Result<()>

Set with lock

Source

pub async fn set_unlocked( &self, address: &str, value: impl Into<Value>, ) -> Result<()>

Set and unlock (release a previously held lock)

Source

pub async fn get(&self, address: &str) -> Result<Value>

Get current value (cached or request)

Source

pub async fn emit(&self, address: &str, payload: impl Into<Value>) -> Result<()>

Emit an event

Source

pub async fn stream(&self, address: &str, value: impl Into<Value>) -> Result<()>

Send stream sample

Source

pub async fn gesture( &self, address: &str, id: u32, phase: GesturePhase, payload: impl Into<Value>, ) -> Result<()>

Send gesture input

Gestures are phased input streams for touch/pen/motion input. Each gesture has a stable ID and goes through phases:

  • Start: Begin a new gesture
  • Move: Update position/state (may be coalesced by router)
  • End: Complete the gesture normally
  • Cancel: Abort the gesture
§Example
// Start a touch gesture
client.gesture("/input/touch", 1, GesturePhase::Start, json!({"x": 0.5, "y": 0.3})).await?;

// Move updates
client.gesture("/input/touch", 1, GesturePhase::Move, json!({"x": 0.6, "y": 0.4})).await?;

// End the gesture
client.gesture("/input/touch", 1, GesturePhase::End, json!({"x": 0.7, "y": 0.5})).await?;
Source

pub async fn timeline( &self, address: &str, timeline_data: TimelineData, ) -> Result<()>

Publish timeline automation

Timelines are pre-computed automation curves with keyframes. Once published, timelines are immutable - to modify, publish a new one.

§Arguments
  • address - The parameter address this timeline controls
  • timeline - The timeline data with keyframes
§Example
use clasp_core::{TimelineData, TimelineKeyframe, EasingType, Value};

let timeline = TimelineData::new(vec![
    TimelineKeyframe { time: 0, value: Value::Float(0.0), easing: EasingType::Linear, bezier: None },
    TimelineKeyframe { time: 1_000_000, value: Value::Float(1.0), easing: EasingType::EaseOut, bezier: None },
]);

client.timeline("/lights/master/dimmer", timeline).await?;
Source

pub async fn bundle(&self, messages: Vec<Message>) -> Result<()>

Send atomic bundle

Source

pub async fn bundle_at(&self, messages: Vec<Message>, time: u64) -> Result<()>

Send scheduled bundle

Source

pub fn cached(&self, address: &str) -> Option<Value>

Get cached param value

Source

pub async fn close(&self)

Close connection. Disables auto-reconnect and closes the connection.

Source

pub fn signals(&self) -> Vec<SignalDefinition>

Get all announced signals

Source

pub fn query_signals(&self, pattern: &str) -> Vec<SignalDefinition>

Query signals matching a pattern

Source

pub fn last_error(&self) -> Option<ErrorMessage>

Get the last error received from server

Source

pub fn clear_error(&self)

Clear the last error

Auto Trait Implementations§

§

impl !Freeze for Clasp

§

impl !RefUnwindSafe for Clasp

§

impl Send for Clasp

§

impl Sync for Clasp

§

impl Unpin for Clasp

§

impl !UnwindSafe for Clasp

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more