Skip to main content

HaystackClient

Struct HaystackClient 

Source
pub struct HaystackClient<T: Transport> { /* private fields */ }
Expand description

A client for communicating with a Haystack HTTP API server.

Provides typed methods for all standard Haystack ops (about, read, hisRead, etc.) as well as a generic call method for custom ops.

Supports both HTTP and WebSocket transports.

Implementations§

Source§

impl HaystackClient<HttpTransport>

Source

pub async fn connect( url: &str, username: &str, password: &str, ) -> Result<Self, ClientError>

Connect to a Haystack server via HTTP, performing SCRAM authentication.

§Arguments
  • url - The server API root (e.g. http://localhost:8080/api)
  • username - The username to authenticate as
  • password - The user’s plaintext password
Source§

impl HaystackClient<WsTransport>

Source

pub async fn connect_ws( url: &str, ws_url: &str, username: &str, password: &str, ) -> Result<Self, ClientError>

Connect to a Haystack server via WebSocket.

Performs SCRAM authentication over HTTP first to obtain an auth token, then establishes a WebSocket connection using that token.

§Arguments
  • url - The server API root for HTTP auth (e.g. http://localhost:8080/api)
  • ws_url - The WebSocket URL (e.g. ws://localhost:8080/api/ws)
  • username - The username to authenticate as
  • password - The user’s plaintext password
Source§

impl<T: Transport> HaystackClient<T>

Source

pub fn from_transport(transport: T) -> Self

Create a client with an already-configured transport.

Source

pub async fn call(&self, op: &str, req: &HGrid) -> Result<HGrid, ClientError>

Call a raw Haystack op with a request grid.

Source

pub async fn about(&self) -> Result<HGrid, ClientError>

Call the about op. Returns server information.

Source

pub async fn ops(&self) -> Result<HGrid, ClientError>

Call the ops op. Returns the list of operations supported by the server.

Source

pub async fn formats(&self) -> Result<HGrid, ClientError>

Call the formats op. Returns the list of MIME formats supported by the server.

Source

pub async fn libs(&self) -> Result<HGrid, ClientError>

Call the libs op. Returns the library modules installed on the server.

Source

pub async fn read( &self, filter: &str, limit: Option<usize>, ) -> Result<HGrid, ClientError>

Call the read op with a filter expression and optional limit.

Source

pub async fn read_by_ids(&self, ids: &[&str]) -> Result<HGrid, ClientError>

Call the read op with a list of entity ids.

Source

pub async fn nav(&self, nav_id: Option<&str>) -> Result<HGrid, ClientError>

Call the nav op. If nav_id is None, returns the root navigation tree.

Source

pub async fn defs(&self, filter: Option<&str>) -> Result<HGrid, ClientError>

Call the defs op with an optional filter.

Source

pub async fn watch_sub( &self, ids: &[&str], lease: Option<&str>, ) -> Result<HGrid, ClientError>

Call the watchSub op to subscribe to a set of entity ids.

lease is an optional lease duration (e.g. "1min").

Source

pub async fn watch_poll(&self, watch_id: &str) -> Result<HGrid, ClientError>

Call the watchPoll op to poll a watch for changes.

Source

pub async fn watch_unsub( &self, watch_id: &str, ids: &[&str], ) -> Result<HGrid, ClientError>

Call the watchUnsub op to unsubscribe from a watch.

Source

pub async fn point_write( &self, id: &str, level: u8, val: Kind, ) -> Result<HGrid, ClientError>

Call the pointWrite op to write a value to a writable point.

Source

pub async fn his_read( &self, id: &str, range: &str, ) -> Result<HGrid, ClientError>

Call the hisRead op to read historical data for a point.

range is a Haystack date range string (e.g. "today", "yesterday", "2024-01-01,2024-01-31").

Source

pub async fn his_write( &self, id: &str, items: Vec<HDict>, ) -> Result<HGrid, ClientError>

Call the hisWrite op to write historical data for a point.

items should be dicts with ts and val tags.

Source

pub async fn invoke_action( &self, id: &str, action: &str, args: HDict, ) -> Result<HGrid, ClientError>

Call the invokeAction op to invoke an action on an entity.

Source

pub async fn close_session(&self) -> Result<HGrid, ClientError>

Call the close op to close the current server session.

This is distinct from close which shuts down the underlying transport connection.

Source

pub async fn specs(&self, lib: Option<&str>) -> Result<HGrid, ClientError>

List all specs, optionally filtered by library name.

Source

pub async fn spec(&self, qname: &str) -> Result<HGrid, ClientError>

Get a single spec by qualified name.

Source

pub async fn load_lib( &self, name: &str, source: &str, ) -> Result<HGrid, ClientError>

Load a Xeto library from source text.

Source

pub async fn unload_lib(&self, name: &str) -> Result<HGrid, ClientError>

Unload a library by name.

Source

pub async fn export_lib(&self, name: &str) -> Result<HGrid, ClientError>

Export a library to Xeto source text.

Source

pub async fn validate(&self, entities: Vec<HDict>) -> Result<HGrid, ClientError>

Validate entities against the server’s ontology.

Source

pub async fn close(&self) -> Result<(), ClientError>

Close the transport connection.

Auto Trait Implementations§

§

impl<T> Freeze for HaystackClient<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for HaystackClient<T>
where T: RefUnwindSafe,

§

impl<T> Send for HaystackClient<T>

§

impl<T> Sync for HaystackClient<T>

§

impl<T> Unpin for HaystackClient<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for HaystackClient<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for HaystackClient<T>
where T: UnwindSafe,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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