amaters_sdk_rust/
lib.rs

1//! # AmateRS SDK for Rust
2//!
3//! This is the official Rust SDK for AmateRS, a Fully Homomorphic Encrypted Database.
4//!
5//! ## Features
6//!
7//! - **Client-side encryption**: All encryption/decryption happens on the client
8//! - **Connection pooling**: Efficient connection management with automatic reconnection
9//! - **Retry logic**: Automatic retries with exponential backoff
10//! - **Type-safe queries**: Fluent API for building queries
11//! - **Async-first**: Built on Tokio for high performance
12//!
13//! ## Quick Start
14//!
15//! ```no_run
16//! use amaters_sdk_rust::{AmateRSClient, ClientConfig};
17//! use amaters_core::{Key, CipherBlob};
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//!     // Connect to server
22//!     let client = AmateRSClient::connect("http://localhost:50051").await?;
23//!
24//!     // Set a value
25//!     let key = Key::from_str("user:123");
26//!     let value = CipherBlob::new(vec![1, 2, 3, 4]);
27//!     client.set("users", &key, &value).await?;
28//!
29//!     // Get a value
30//!     if let Some(retrieved) = client.get("users", &key).await? {
31//!         println!("Retrieved {} bytes", retrieved.len());
32//!     }
33//!
34//!     // Delete a key
35//!     client.delete("users", &key).await?;
36//!
37//!     Ok(())
38//! }
39//! ```
40//!
41//! ## Connection Configuration
42//!
43//! ```no_run
44//! use amaters_sdk_rust::{AmateRSClient, ClientConfig, RetryConfig};
45//! use std::time::Duration;
46//!
47//! # async fn example() -> anyhow::Result<()> {
48//! let config = ClientConfig::new("http://localhost:50051")
49//!     .with_connect_timeout(Duration::from_secs(5))
50//!     .with_request_timeout(Duration::from_secs(30))
51//!     .with_max_connections(20)
52//!     .with_retry_config(
53//!         RetryConfig::new()
54//!             .with_max_retries(5)
55//!             .with_initial_backoff(Duration::from_millis(100))
56//!     );
57//!
58//! let client = AmateRSClient::connect_with_config(config).await?;
59//! # Ok(())
60//! # }
61//! ```
62//!
63//! ## Query Builder
64//!
65//! ```no_run
66//! use amaters_sdk_rust::query;
67//! use amaters_core::{Key, CipherBlob, col, Predicate};
68//!
69//! # async fn example() {
70//! // Simple query
71//! let q = query("users").get(Key::from_str("user:123"));
72//!
73//! // Filter with predicates
74//! let q = query("users")
75//!     .where_clause()
76//!     .eq(col("status"), CipherBlob::new(vec![1]))
77//!     .and(Predicate::Gt(col("age"), CipherBlob::new(vec![18])))
78//!     .build();
79//!
80//! // Range query
81//! let q = query("data").range(
82//!     Key::from_str("start"),
83//!     Key::from_str("end")
84//! );
85//! # }
86//! ```
87//!
88//! ## FHE Integration
89//!
90//! The SDK supports client-side encryption with FHE (feature-gated):
91//!
92//! ```no_run
93//! use amaters_sdk_rust::{AmateRSClient, FheEncryptor};
94//!
95//! # async fn example() -> anyhow::Result<()> {
96//! // Create encryptor (stub implementation for now)
97//! let encryptor = FheEncryptor::new()?;
98//!
99//! // Connect with encryptor
100//! let client = AmateRSClient::connect("http://localhost:50051")
101//!     .await?
102//!     .with_encryptor(encryptor);
103//! # Ok(())
104//! # }
105//! ```
106//!
107//! ## Feature Flags
108//!
109//! - `fhe` - Enable full FHE support with TFHE
110//! - `serialization` - Enable key serialization with oxicode
111
112#![allow(dead_code)]
113#![allow(clippy::type_complexity)]
114
115pub mod client;
116pub mod config;
117pub mod connection;
118pub mod error;
119pub mod fhe;
120pub mod query;
121
122// Re-export main types
123pub use client::{AmateRSClient, QueryResult, ServerInfo};
124pub use config::{ClientConfig, RetryConfig, TlsConfig};
125pub use error::{Result, SdkError};
126pub use fhe::{FheEncryptor, FheKeys};
127pub use query::{FilterBuilder, FluentQueryBuilder, PredicateBuilder, query};
128
129// Re-export core types for convenience
130pub use amaters_core::{CipherBlob, ColumnRef, Key, Predicate, Query, Update, col};
131
132/// Library version
133pub const VERSION: &str = env!("CARGO_PKG_VERSION");
134
135#[cfg(test)]
136mod tests {
137    use super::*;
138
139    #[test]
140    #[allow(clippy::len_zero)]
141    fn test_version() {
142        // Just verify it's defined - no need to check is_empty since it's a const
143        assert!(VERSION.len() > 0);
144    }
145
146    #[test]
147    fn test_exports() {
148        // Test that main types are accessible
149        let _config = ClientConfig::default();
150        let _retry = RetryConfig::default();
151    }
152}