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