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