Skip to main content

cloud_sdk/
client.rs

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