Skip to main content

perspective_client/
lib.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13//! `perspective_client` is the client implementation of
14//! [Perspective](https://perspective-dev.github.io), designed to be used from Rust
15//! directly, and as a core to `perspective-js` and `perspective-python` crates
16//! which wrap language-specific bindings for this module.
17//!
18//! # See also
19//!
20//! - [`perspective-rs`](https://docs.rs/perspective/latest/) for the Rust
21//!   Client and Server APIs.
22//! - [`perspective-js`](https://docs.rs/perspective-js/latest/) for the
23//!   JavaScript API.
24//! - [`perspective-python`](https://docs.rs/perspective-python/latest/) for the
25//!   Python API.
26//! - [`perspective-server`](https://docs.rs/perspective-server/latest/) for
27//!   Data Binding details.
28//! - [`perspective-viewer`](https://docs.rs/perspective-viewer/latest/) for the
29//!   WebAssembly `<perspective-viewer>` Custom Element API.
30
31#![warn(
32    clippy::all,
33    clippy::panic_in_result_fn,
34    clippy::await_holding_refcell_ref
35)]
36
37mod client;
38mod session;
39mod table;
40mod table_data;
41mod view;
42pub mod virtual_server;
43
44pub mod config;
45
46#[rustfmt::skip]
47#[allow(clippy::all)]
48pub mod proto;
49
50pub mod utils;
51
52pub use crate::client::{Client, ClientHandler, Features, ReconnectCallback, SystemInfo};
53use crate::proto::HostedTable;
54pub use crate::session::{ProxySession, Session};
55pub use crate::table::{
56    DeleteOptions, ExprValidationResult, Table, TableInitOptions, TableReadFormat, UpdateOptions,
57};
58pub use crate::table_data::{TableData, UpdateData};
59pub use crate::view::{
60    ColumnWindow, OnUpdateData, OnUpdateMode, OnUpdateOptions, View, ViewWindow,
61};
62
63pub type ClientError = utils::ClientError;
64pub type ExprValidationError = crate::proto::table_validate_expr_resp::ExprValidationError;
65
66#[doc(hidden)]
67pub mod vendor {
68    pub use paste;
69}
70
71impl From<&str> for HostedTable {
72    fn from(entity_id: &str) -> Self {
73        HostedTable {
74            entity_id: entity_id.to_string(),
75            index: None,
76            limit: None,
77        }
78    }
79}
80
81/// Assert that an implementation of domain language wrapper for [`Table`]
82/// implements the expected API. As domain languages have different API needs,
83/// a trait isn't useful for asserting that the entire API is implemented,
84/// because the signatures will not match exactly (unless every method is
85/// made heavily generic). Instead, this macro complains when a method name
86/// is missing.
87#[doc(hidden)]
88#[macro_export]
89macro_rules! assert_table_api {
90    ($x:ty) => {
91        $crate::vendor::paste::paste! {
92            #[cfg(debug_assertions)]
93            fn [< _assert_table_api_ $x:lower >]() {
94                let _ = (
95                    &$x::clear,
96                    &$x::columns,
97                    &$x::delete,
98                    &$x::get_index,
99                    &$x::get_limit,
100                    &$x::get_client,
101                    &$x::make_port,
102                    &$x::on_delete,
103                    &$x::remove_delete,
104                    &$x::replace,
105                    &$x::schema,
106                    &$x::size,
107                    &$x::update,
108                    &$x::validate_expressions,
109                    &$x::view,
110                );
111            }
112        }
113    };
114}
115
116/// Similar to [`assert_table_api`], but for [`View`]. See [`assert_table_api`].
117#[doc(hidden)]
118#[macro_export]
119macro_rules! assert_view_api {
120    ($x:ty) => {
121        $crate::vendor::paste::paste! {
122            #[cfg(debug_assertions)]
123            fn [< _assert_table_api_ $x:lower >]() {
124                let _ = (
125                    &$x::column_paths,
126                    &$x::delete,
127                    &$x::dimensions,
128                    &$x::expression_schema,
129                    &$x::get_config,
130                    &$x::get_min_max,
131                    &$x::num_rows,
132                  //  &$x::on_update,
133                    &$x::remove_update,
134                    &$x::on_delete,
135                    &$x::remove_delete,
136                    &$x::schema,
137                    &$x::to_arrow,
138                    &$x::to_columns_string,
139                    &$x::to_json_string,
140                    &$x::to_csv,
141                );
142            }
143        }
144    };
145}