Skip to main content

cloud_sdk/
client.rs

1//! Provider-generic typed client execution over caller-owned workspaces.
2
3mod error;
4mod execution;
5mod response;
6mod workspace;
7
8pub use error::ClientExecutionError;
9pub use response::{CheckedDecodeError, ClientResponse, ClientResponseKind};
10pub use workspace::{
11    ClientWorkspace, ClientWorkspaceLease, ClientWorkspacePool, MAX_CLIENT_WORKSPACE_LEASES,
12    WorkspaceAcquireError, WorkspacePoolError,
13};
14
15use core::fmt;
16
17use crate::operation::PrepareOperation;
18
19type ClientResult<R, P, T, D> = Result<R, ClientExecutionError<P, T, D>>;
20
21/// Typed provider operation executable by [`ClientKernel`].
22///
23/// Preparation binds method, target, authentication, endpoint, response, and
24/// safety policy. Decoding must consume [`ClientResponse`] through its checked
25/// success or error path and return an owned value.
26pub trait ClientOperation: PrepareOperation {
27    /// Owned operation result.
28    type Output;
29    /// Provider-specific checked-decoding failure.
30    type DecodeError;
31
32    /// Decodes one bounded, authenticated, send-once response.
33    fn decode_response(
34        &self,
35        response: ClientResponse<'_, '_>,
36    ) -> Result<Self::Output, Self::DecodeError>;
37}
38
39/// Reusable provider-neutral client policy kernel.
40///
41/// The kernel owns only its transport. It owns no executor, queue, clock,
42/// retry policy, or request storage. Every in-flight request must consume a
43/// caller-owned [`ClientWorkspaceLease`].
44pub struct ClientKernel<T> {
45    transport: T,
46}
47
48impl<T> ClientKernel<T> {
49    /// Creates a kernel around one endpoint-bound authenticated transport.
50    #[must_use]
51    pub const fn new(transport: T) -> Self {
52        Self { transport }
53    }
54
55    /// Returns the underlying transport.
56    #[must_use]
57    pub const fn transport(&self) -> &T {
58        &self.transport
59    }
60
61    /// Consumes the kernel and returns its transport.
62    #[must_use]
63    pub fn into_transport(self) -> T {
64        self.transport
65    }
66}
67
68impl<T> fmt::Debug for ClientKernel<T> {
69    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
70        formatter
71            .debug_struct("ClientKernel")
72            .field("transport", &"[bound]")
73            .finish()
74    }
75}
76
77#[cfg(test)]
78mod tests;