pub struct Client { /* private fields */ }Expand description
An instance of a Client is a connection to a single
perspective_server::Server, whether locally in-memory or remote over some
transport like a WebSocket.
§Examples
Create a perspective_server::Server and a synchronous Client via the
perspective crate:
use perspective::LocalClient;
use perspective::server::Server;
let server = Server::default();
let client = perspective::LocalClient::new(&server);Implementations§
Source§impl Client
impl Client
Sourcepub fn new_with_callback<T, U>(
name: Option<&str>,
send_request: T,
) -> ClientResult<Self>
pub fn new_with_callback<T, U>( name: Option<&str>, send_request: T, ) -> ClientResult<Self>
Create a new client instance with a closure that handles message
dispatch. See Client::new for details.
Sourcepub fn new<T>(name: Option<&str>, client_handler: T) -> ClientResult<Self>
pub fn new<T>(name: Option<&str>, client_handler: T) -> ClientResult<Self>
Create a new Client instance with ClientHandler.
pub fn get_name(&self) -> &str
Sourcepub async fn handle_response<'a>(&'a self, msg: &'a [u8]) -> ClientResult<bool>
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.
Sourcepub async fn handle_error<T, U>(
&self,
message: ClientError,
reconnect: Option<T>,
) -> ClientResult<()>
pub async fn handle_error<T, U>( &self, message: ClientError, reconnect: Option<T>, ) -> ClientResult<()>
Handle an exception from the underlying transport.
pub async fn on_error<T, U, V>(&self, on_error: T) -> ClientResult<u32>where
T: Fn(ClientError, Option<ReconnectCallback>) -> U + Clone + Send + Sync + 'static,
U: Future<Output = V> + Send + 'static,
V: Into<Result<(), ClientError>> + Sync + 'static,
Sourcepub async fn table(
&self,
input: TableData,
options: TableInitOptions,
) -> ClientResult<Table>
pub async fn table( &self, input: TableData, options: TableInitOptions, ) -> ClientResult<Table>
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 resultingTablecan store.index- The column name to use as an index column. If thisTableis 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?;Sourcepub async fn open_table(&self, entity_id: String) -> ClientResult<Table>
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 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;Sourcepub async fn get_hosted_table_names(&self) -> ClientResult<Vec<String>>
pub async fn get_hosted_table_names(&self) -> ClientResult<Vec<String>>
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;Sourcepub async fn on_hosted_tables_update<T, U>(
&self,
on_update: T,
) -> ClientResult<u32>
pub async fn on_hosted_tables_update<T, U>( &self, on_update: T, ) -> ClientResult<u32>
Register a callback which is invoked whenever Client::table (on this
Client) or Table::delete (on a Table belinging to this
Client) are called.
Sourcepub async fn remove_hosted_tables_update(
&self,
update_id: u32,
) -> ClientResult<()>
pub async fn remove_hosted_tables_update( &self, update_id: u32, ) -> ClientResult<()>
Remove a callback previously registered via
Client::on_hosted_tables_update.
Sourcepub async fn system_info(&self) -> ClientResult<SystemInfo>
pub async fn system_info(&self) -> ClientResult<SystemInfo>
Provides the SystemInfo struct, implementation-specific metadata
about the [perspective_server::Server] runtime such as Memory and
CPU usage.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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