d_engine/client/client.rs
1//! Distributed consensus client implementation
2//!
3//! Contains the primary interface [`Client`] that combines:
4//! - Key-value store operations through [`KvClient`]
5//! - Cluster management via [`ClusterClient`]
6//!
7//! Manages connection pooling and request routing to cluster nodes.
8
9use super::ClientBuilder;
10use super::ClusterClient;
11use super::KvClient;
12
13/// Main entry point for interacting with the d_engine cluster
14///
15/// Manages connections and provides access to specialized clients:
16/// - Use [`kv()`](Client::kv) for data operations
17/// - Use [`cluster()`](Client::cluster) for cluster administration
18///
19/// Created through the [`builder()`](Client::builder) method
20pub struct Client {
21 /// Key-value store client interface
22 pub kv: KvClient,
23
24 /// Cluster management client interface
25 pub cluster: ClusterClient,
26}
27
28impl Client {
29 /// Access the key-value operations client
30 ///
31 /// # Examples
32 /// ```rust,ignore
33 /// client.kv().put("key", "value").await?;
34 /// ```
35 pub fn kv(&self) -> &KvClient {
36 &self.kv
37 }
38
39 /// Access the cluster management client
40 ///
41 /// # Examples
42 /// ```rust,ignore
43 /// client.cluster().add_node("node3:9083").await?;
44 /// ```
45 pub fn cluster(&self) -> &ClusterClient {
46 &self.cluster
47 }
48
49 /// Create a configured client builder
50 ///
51 /// Starts client construction process with specified bootstrap endpoints.
52 /// Chain configuration methods before calling
53 /// [`build()`](ClientBuilder::build).
54 ///
55 /// # Arguments
56 /// * `endpoints` - Initial cluster nodes for discovery
57 ///
58 /// # Panics
59 /// Will panic if no valid endpoints provided
60 pub fn builder(endpoints: Vec<String>) -> ClientBuilder {
61 assert!(!endpoints.is_empty(), "At least one endpoint required");
62 ClientBuilder::new(endpoints)
63 }
64}