Skip to main content

cloud_sdk/
client.rs

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