Skip to main content

Client

Struct Client 

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

Main Commy client for interacting with a Commy server

Implementations§

Source§

impl Client

Source

pub async fn initialize( server_url: impl Into<String>, tenant_id: impl Into<String>, credentials: AuthCredentials, ) -> Result<Self>

Initialize a fully-configured client in one call

This is the primary entry point. It:

  1. Creates a new client
  2. Connects to the server
  3. Authenticates to the tenant
  4. Initializes the file watcher
  5. Starts file monitoring

After this, the client is ready to use with get_virtual_service_file().

Source

pub fn new(server_url: impl Into<String>) -> Self

Create a new client (public - for testing/special cases)

Source

pub fn with_id( server_url: impl Into<String>, client_id: impl Into<String>, ) -> Self

Create a new client with custom ID

Source

pub fn id(&self) -> &str

Get client ID

Source

pub fn server_url(&self) -> &str

Get server URL

Source

pub async fn connect(&self) -> Result<()>

Connect to server (public - for testing/special cases)

Source

pub async fn authenticate( &self, tenant_id: impl Into<String>, credentials: AuthCredentials, ) -> Result<AuthContext>

Authenticate to a tenant (public - for testing/special cases)

Source

pub async fn create_service( &self, tenant_id: &str, service_name: &str, ) -> Result<String>

Create a new service in a tenant

Returns the service ID on success. Returns error if:

  • Not authenticated to the tenant
  • Service already exists
  • Insufficient permissions (need create_service permission)
Source

pub async fn get_service( &self, tenant_id: &str, service_name: &str, ) -> Result<Service>

Get an existing service from a tenant (read-only, no side effects)

Returns error if:

  • Not authenticated to the tenant
  • Service does not exist (NotFound error)
  • Insufficient permissions (need read_service permission)
Source

pub async fn delete_service( &self, tenant_id: &str, service_name: &str, ) -> Result<()>

Delete a service from a tenant

Returns error if:

  • Not authenticated to the tenant
  • Service does not exist
  • Insufficient permissions (need delete_service permission, typically admin)
Source

pub async fn create_tenant( &self, tenant_id: &str, tenant_name: &str, ) -> Result<String>

Create a new tenant (admin operation)

Requires admin credentials or special permissions to create tenants. Returns the tenant ID on success.

Returns error if:

  • Not connected to server
  • Tenant already exists
  • Insufficient permissions (need admin role)
Source

pub async fn delete_tenant(&self, tenant_id: &str) -> Result<()>

Delete a tenant (admin operation)

Removes all services and data associated with the tenant. Requires admin credentials or special permissions.

Returns error if:

  • Not connected to server
  • Tenant does not exist
  • Insufficient permissions (need admin role)
  • Tenant has active clients
Source

pub async fn read_variable( &self, service_id: &str, variable_name: &str, ) -> Result<Vec<u8>>

Read a variable value

Source

pub async fn write_variable( &self, service_id: &str, variable_name: &str, data: Vec<u8>, ) -> Result<()>

Write a variable value

Source

pub async fn subscribe( &self, service_id: &str, variable_name: &str, ) -> Result<()>

Subscribe to variable changes

Source

pub async fn unsubscribe( &self, service_id: &str, variable_name: &str, ) -> Result<()>

Unsubscribe from variable changes

Source

pub async fn heartbeat(&self) -> Result<()>

Send heartbeat to server

Source

pub async fn disconnect(&self) -> Result<()>

Disconnect from server

Source

pub async fn is_connected(&self) -> bool

Check if connected

Source

pub async fn connection_state(&self) -> ConnectionState

Get current connection state

Source

pub async fn authenticated_tenants(&self) -> Vec<String>

Get authenticated tenants

Source

pub async fn is_authenticated_to(&self, tenant_id: &str) -> bool

Check if authenticated to tenant

Source

pub async fn idle_seconds(&self) -> u64

Get idle time in seconds

Source

pub async fn init_file_watcher(&self) -> Result<()>

Initialize file watcher for hybrid mode (public - for testing/special cases)

Source

pub async fn get_virtual_service_file( &self, tenant_id: &str, service_name: &str, ) -> Result<Arc<VirtualVariableFile>>

Get or create a virtual variable file for a service

This creates a virtual representation that works seamlessly for both:

  • Local clients: Memory-mapped to actual service file
  • Remote clients: In-memory buffer synced via WSS
Source

pub async fn start_file_monitoring(&self) -> Result<()>

Start monitoring virtual files for changes (public - for testing/special cases)

This spawns a background task that watches for file changes and automatically detects which variables have changed using SIMD

Source

pub async fn wait_for_file_change(&self) -> Result<Option<FileChangeEvent>>

Get next file change event (blocks until a file changes)

Source

pub async fn try_get_file_change(&self) -> Result<Option<FileChangeEvent>>

Try to get next file change event (non-blocking)

Source

pub async fn stop_file_monitoring(&self) -> Result<()>

Stop file monitoring

Auto Trait Implementations§

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, 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