Struct perspective_client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

An instance of a Client is a unique connection to a single Server, whether locally in-memory or remote over some transport like a WebSocket. To create, use the appropriate constructor function:

  • websocket - Create a connection to a WebSocket Server instance.
  • worker (JavaScript) - Unlike the other Client constructors, the worker version also owns its Server, which runs in a dedicated Web Worker.
  • local [Rust, Python] - Create an Client connected to an in-memory, in-process Server.

§Examples

§JavaScript
const client = await perspective.worker();

Implementations§

source§

impl Client

source

pub fn new_with_callback<T>(send_request: T) -> Self
where T: for<'a> Fn(&'a [u8]) -> BoxFuture<'a, Result<(), Box<dyn Error + Send + Sync>>> + 'static + Sync + Send,

Create a new client instance with a closure that handles message dispatch. See Client::new for details.

source

pub fn new<T>(client_handler: T) -> Self
where T: ClientHandler + 'static + Sync + Send,

Create a new Client instance with ClientHandler.

source

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

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 init(&self) -> ClientResult<()>

source

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

Creates a new Table from either a schema or data. The [table()] factory function can be initialized with either a schema, or data in one of these formats:

  • Apache Arrow, as [pyo3::bytes] (python) or [js_sys::ArrayBuffer] (js)
  • CSV as a String
  • Row-oriented [pyo3::list] (python) or [js_sys::Array] (js)
  • Column-oriented [pyo3::dict] (python) or [js_sys::Object] (js)

When instantiated with data, the schema is inferred from this data. Future calls to Table::update will coerce to the inferred type this schema. While this is convenient, inferrence is sometimes imperfect e.g. when the input is empty, null or ambiguous. For these cases, Client::table can 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 Server from which it was instantiated (e.g. a Web Worker or WebSocket client), 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.
§Examples
§JavaScript
// Load a CSV
const table = await client.table("x,y\n1,2\n3,4");

// Load an Arrow
import * as fs from "node:fs/promises";
const table2 = await client.table(await fs.readFile("superstore.arrow"));
§Python
table = await client.table("x,y\n1,2\n3,4")
§Rust
let table = client.table(TableData::FromCsv("x,y\n1,2\n3,4")).await?;
source

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

Opens a Table that is hosted on the [perspective_server::Server] that is connected to this Client. The name property of TableInitOptions

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

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

Retrieves the names of all tables that this client has access to. This can be used in conjunction with Client::open_table.

§Arguments

None.

§Examples
const tables = await client.get_hosted_table_names();
tables = await async_client.get_hosted_table_names();
let tables = client.get_hosted_table_names().await;
source

pub async fn system_info(&self) -> ClientResult<SystemInfo>

Provides the [perspective_client::SystemInfo] struct.

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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