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