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;
42
43pub mod config;
44
45#[rustfmt::skip]
46#[allow(clippy::all)]
47mod proto;
48
49pub mod utils;
50
51pub use crate::client::{Client, ClientHandler, Features, ReconnectCallback, SystemInfo};
52pub use crate::session::{ProxySession, Session};
53pub use crate::table::{
54    DeleteOptions, ExprValidationResult, Table, TableInitOptions, TableReadFormat, UpdateOptions,
55};
56pub use crate::table_data::{TableData, UpdateData};
57pub use crate::view::{
58    ColumnWindow, OnUpdateData, OnUpdateMode, OnUpdateOptions, View, ViewWindow,
59};
60
61pub type ClientError = utils::ClientError;
62pub type ExprValidationError = crate::proto::table_validate_expr_resp::ExprValidationError;
63
64#[doc(hidden)]
65pub mod vendor {
66    pub use paste;
67}
68
69/// Assert that an implementation of domain language wrapper for [`Table`]
70/// implements the expected API. As domain languages have different API needs,
71/// a trait isn't useful for asserting that the entire API is implemented,
72/// because the signatures will not match exactly (unless every method is
73/// made heavily generic). Instead, this macro complains when a method name
74/// is missing.
75#[doc(hidden)]
76#[macro_export]
77macro_rules! assert_table_api {
78    ($x:ty) => {
79        $crate::vendor::paste::paste! {
80            #[cfg(debug_assertions)]
81            fn [< _assert_table_api_ $x:lower >]() {
82                let _ = (
83                    &$x::clear,
84                    &$x::columns,
85                    &$x::delete,
86                    &$x::get_index,
87                    &$x::get_limit,
88                    &$x::get_client,
89                    &$x::make_port,
90                    &$x::on_delete,
91                    &$x::remove_delete,
92                    &$x::replace,
93                    &$x::schema,
94                    &$x::size,
95                    &$x::update,
96                    &$x::validate_expressions,
97                    &$x::view,
98                );
99            }
100        }
101    };
102}
103
104/// Similar to [`assert_table_api`], but for [`View`]. See [`assert_table_api`].
105#[doc(hidden)]
106#[macro_export]
107macro_rules! assert_view_api {
108    ($x:ty) => {
109        $crate::vendor::paste::paste! {
110            #[cfg(debug_assertions)]
111            fn [< _assert_table_api_ $x:lower >]() {
112                let _ = (
113                    &$x::column_paths,
114                    &$x::delete,
115                    &$x::dimensions,
116                    &$x::expression_schema,
117                    &$x::get_config,
118                    &$x::get_min_max,
119                    &$x::num_rows,
120                  //  &$x::on_update,
121                    &$x::remove_update,
122                    &$x::on_delete,
123                    &$x::remove_delete,
124                    &$x::schema,
125                    &$x::to_arrow,
126                    &$x::to_columns_string,
127                    &$x::to_json_string,
128                    &$x::to_csv,
129                );
130            }
131        }
132    };
133}