|
9 | 9 |
|
10 | 10 | mod http; |
11 | 11 |
|
| 12 | +use core::future::Future; |
| 13 | + |
12 | 14 | pub use http::DefaultHttpClient; |
| 15 | +use libdd_capabilities::http::HttpError; |
13 | 16 | pub use libdd_capabilities::HttpClientTrait; |
| 17 | +use libdd_capabilities::MaybeSend; |
14 | 18 |
|
15 | 19 | /// Bundle struct for native platform capabilities. |
16 | 20 | /// |
17 | | -/// Currently delegates to `DefaultHttpClient` for HTTP. As more capability |
18 | | -/// traits are added (spawn, sleep, etc.), this type will become a proper struct |
19 | | -/// implementing all of them. |
| 21 | +/// Delegates to [`DefaultHttpClient`] for HTTP. As more capability traits are |
| 22 | +/// added (spawn, sleep, etc.), additional fields and impls are added here |
| 23 | +/// without changing the type identity — consumers see the same |
| 24 | +/// `NativeCapabilities` throughout. |
20 | 25 | /// |
21 | | -/// At that point, consider introducing a `CapabilitiesBundle` trait in |
22 | | -/// `libdd-capabilities` with a `fn new() -> Self` constructor, so that bundle |
23 | | -/// creation is decoupled from `HttpClientTrait::new_client()`. Individual |
24 | | -/// capability traits should keep minimal per-function bounds (e.g. functions |
25 | | -/// that only need HTTP should require just `H: HttpClientTrait`, not the full |
26 | | -/// bundle) as this lets native callers like the sidecar use `DefaultHttpClient` |
27 | | -/// directly without pulling in the full bundle. |
28 | | -pub type NativeCapabilities = DefaultHttpClient; |
| 26 | +/// Individual capability traits keep minimal per-function bounds (e.g. |
| 27 | +/// functions that only need HTTP require just `H: HttpClientTrait`, not the |
| 28 | +/// full bundle) so that native callers like the sidecar can use |
| 29 | +/// `DefaultHttpClient` directly without pulling in this bundle. |
| 30 | +#[derive(Clone, Debug)] |
| 31 | +pub struct NativeCapabilities { |
| 32 | + http: DefaultHttpClient, |
| 33 | +} |
| 34 | + |
| 35 | +impl HttpClientTrait for NativeCapabilities { |
| 36 | + fn new_client() -> Self { |
| 37 | + Self { |
| 38 | + http: DefaultHttpClient::new_client(), |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + fn request( |
| 43 | + &self, |
| 44 | + req: ::http::Request<bytes::Bytes>, |
| 45 | + ) -> impl Future<Output = Result<::http::Response<bytes::Bytes>, HttpError>> + MaybeSend { |
| 46 | + self.http.request(req) |
| 47 | + } |
| 48 | +} |
0 commit comments