Struct LocalClient

Source
pub struct LocalClient(/* private fields */);
Expand description

A Client specialized for connecting to an in-process Server.

Implementations§

Source§

impl LocalClient

Source

pub fn new(server: &Server) -> Self

Create a new LocalClient instance for a Server.

Source

pub fn take(self) -> Result<Client, &'static str>

Source

pub async fn close(self)

Close this LocalClient. Dropping a LocalClient instead of calling LocalClient::close will result in a log error, as this will leak!

Methods from Deref<Target = Client>§

Source

pub fn get_name(&self) -> &str

Source

pub async fn handle_response<'a>( &'a self, msg: &'a [u8], ) -> Result<bool, ClientError>

Handle a message from the external message queue. Client::handle_response is part of the low-level message-handling API necessary to implement new transports for a Client connection to a local-or-remote perspective_server::Server, and doesn’t generally need to be called directly by “users” of a Client once connected.

Source

pub async fn handle_error<T, U>( &self, message: ClientError, reconnect: Option<T>, ) -> Result<(), ClientError>
where T: Fn() -> U + Clone + Send + Sync + 'static, U: Future<Output = Result<(), ClientError>>,

Handle an exception from the underlying transport.

Source

pub async fn on_error<T, U, V>(&self, on_error: T) -> Result<u32, ClientError>
where T: Fn(ClientError, Option<Arc<dyn Fn() -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error>>>>> + Send + Sync>>) -> U + Clone + Send + Sync + 'static, U: Future<Output = V> + Send + 'static, V: Into<Result<(), ClientError>> + Sync + 'static,

Source

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

Source

pub async fn table( &self, input: TableData, options: TableInitOptions, ) -> Result<Table, ClientError>

Creates a new Table from either a schema or data.

The Client::table factory function can be initialized with either a schema (see Table::schema), or data in one of these formats:

  • Apache Arrow
  • CSV
  • JSON row-oriented
  • JSON column-oriented
  • NDJSON

When instantiated with data, the schema is inferred from this data. While this is convenient, inferrence is sometimes imperfect e.g. when the input is empty, null or ambiguous. For these cases, Client::table can first be instantiated with a explicit schema.

When instantiated with a schema, the resulting Table is empty but with known column names and column types. When subsqeuently populated with Table::update, these columns will be coerced to the schema’s type. This behavior can be useful when Client::table’s column type inferences doesn’t work.

The resulting Table is virtual, and invoking its methods dispatches events to the perspective_server::Server this Client connects to, where the data is stored and all calculation occurs.

§Arguments
  • arg - Either schema or initialization data.
  • options - Optional configuration which provides one of:
    • limit - The max number of rows the resulting Table can store.
    • index - The column name to use as an index column. If this Table is being instantiated by data, this column name must be present in the data.
    • name - The name of the table. This will be generated if it is not provided.
    • format - The explicit format of the input data, can be one of "json", "columns", "csv" or "arrow". This overrides language-specific type dispatch behavior, which allows stringified and byte array alternative inputs.
§Examples

Load a CSV from a String:

let opts = TableInitOptions::default();
let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
let table = client.table(data, opts).await?;
Source

pub async fn open_table(&self, entity_id: String) -> Result<Table, ClientError>

Opens a Table that is hosted on the perspective_server::Server that is connected to this Client.

The name property of TableInitOptions is used to identify each Table. Table names can be looked up for each Client via Client::get_hosted_table_names.

§Examples
let tables = client.open_table("table_one").await;
Source

pub async fn get_hosted_table_names(&self) -> Result<Vec<String>, ClientError>

Retrieves the names of all tables that this client has access to.

name is a string identifier unique to the Table (per Client), which can be used in conjunction with Client::open_table to get a Table instance without the use of Client::table constructor directly (e.g., one created by another Client).

§Examples
let tables = client.get_hosted_table_names().await;
Source

pub async fn on_hosted_tables_update<T, U>( &self, on_update: T, ) -> Result<u32, ClientError>
where T: Fn() -> U + Send + Sync + 'static, U: Future<Output = ()> + Send + 'static,

Register a callback which is invoked whenever Client::table (on this Client) or Table::delete (on a Table belinging to this Client) are called.

Source

pub async fn remove_hosted_tables_update( &self, update_id: u32, ) -> Result<(), ClientError>

Remove a callback previously registered via Client::on_hosted_tables_update.

Source

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

Provides the SystemInfo struct, implementation-specific metadata about the [perspective_server::Server] runtime such as Memory and CPU usage.

Trait Implementations§

Source§

impl Deref for LocalClient

Source§

type Target = Client

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for LocalClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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