spark_rust/rpc/
traits.rs

1//! Traits and types for establishing RPC connections to Spark nodes.
2//!
3//! This module provides the core trait [`SparkRpcConnection`] which defines how
4//! connections to Spark nodes should be established. It also includes the underlying
5//! raw connection type [`SparkRpcClient`] used by the RPC client.
6//!
7//! The connection implementation handles:
8//! - TLS configuration and certificate verification
9//! - HTTP/2 protocol negotiation
10//! - Connection pooling and management
11//!
12//! # Examples
13//!
14//! Implementations of [`SparkRpcConnection`] are used internally by the SDK to establish
15//! secure connections to Spark nodes. The default implementation uses TLS with certificate
16//! verification disabled for development purposes.
17
18use tonic::async_trait;
19use tonic::transport::Uri;
20
21use crate::error::SparkSdkError;
22
23use super::SparkRpcClient;
24
25/// Trait for establishing RPC connections to Spark nodes.
26///
27/// This trait defines the core functionality needed to create secure connections
28/// to Spark RPC endpoints. Implementations handle the details of TLS configuration,
29/// certificate management, and connection establishment.
30#[async_trait]
31pub trait SparkRpcConnection {
32    /// Establishes a new RPC connection to a Spark node.
33    ///
34    /// # Arguments
35    /// * `uri` - The URI of the Spark node
36    ///
37    /// # Returns
38    /// - `Ok(SparkRpcClient)` if the connection was established successfully
39    /// - `Err(SparkSdkError)` if there was an error establishing the connection
40    async fn establish_connection(uri: Uri) -> Result<SparkRpcClient, SparkSdkError>;
41}