|
9 | 9 |
|
10 | 10 | mod http; |
11 | 11 |
|
12 | | -use core::future::Future; |
| 12 | +pub use libdd_capabilities::HttpClientTrait; |
13 | 13 |
|
| 14 | +#[cfg(not(target_arch = "wasm32"))] |
14 | 15 | pub use http::DefaultHttpClient; |
15 | | -use libdd_capabilities::http::HttpError; |
16 | | -pub use libdd_capabilities::HttpClientTrait; |
17 | | -use libdd_capabilities::MaybeSend; |
18 | | - |
19 | | -/// Bundle struct for native platform capabilities. |
20 | | -/// |
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. |
25 | | -/// |
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 | 16 |
|
35 | | -impl HttpClientTrait for NativeCapabilities { |
36 | | - fn new_client() -> Self { |
37 | | - Self { |
38 | | - http: DefaultHttpClient::new_client(), |
39 | | - } |
| 17 | +#[cfg(not(target_arch = "wasm32"))] |
| 18 | +mod native { |
| 19 | + use core::future::Future; |
| 20 | + |
| 21 | + use libdd_capabilities::http::HttpError; |
| 22 | + use libdd_capabilities::MaybeSend; |
| 23 | + |
| 24 | + use super::DefaultHttpClient; |
| 25 | + use super::HttpClientTrait; |
| 26 | + |
| 27 | + /// Bundle struct for native platform capabilities. |
| 28 | + /// |
| 29 | + /// Delegates to [`DefaultHttpClient`] for HTTP. As more capability traits are |
| 30 | + /// added (spawn, sleep, etc.), additional fields and impls are added here |
| 31 | + /// without changing the type identity — consumers see the same |
| 32 | + /// `NativeCapabilities` throughout. |
| 33 | + /// |
| 34 | + /// Individual capability traits keep minimal per-function bounds (e.g. |
| 35 | + /// functions that only need HTTP require just `H: HttpClientTrait`, not the |
| 36 | + /// full bundle) so that native callers like the sidecar can use |
| 37 | + /// `DefaultHttpClient` directly without pulling in this bundle. |
| 38 | + #[derive(Clone, Debug)] |
| 39 | + pub struct NativeCapabilities { |
| 40 | + http: DefaultHttpClient, |
40 | 41 | } |
41 | 42 |
|
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) |
| 43 | + impl HttpClientTrait for NativeCapabilities { |
| 44 | + fn new_client() -> Self { |
| 45 | + Self { |
| 46 | + http: DefaultHttpClient::new_client(), |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + fn request( |
| 51 | + &self, |
| 52 | + req: ::http::Request<bytes::Bytes>, |
| 53 | + ) -> impl Future<Output = Result<::http::Response<bytes::Bytes>, HttpError>> + MaybeSend |
| 54 | + { |
| 55 | + self.http.request(req) |
| 56 | + } |
47 | 57 | } |
48 | 58 | } |
| 59 | + |
| 60 | +#[cfg(not(target_arch = "wasm32"))] |
| 61 | +pub use native::NativeCapabilities; |
0 commit comments