Skip to content

Commit 8be3832

Browse files
committed
fix: use bundle type instead of alias for capabilities bundle
1 parent 94db151 commit 8be3832

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libdd-capabilities-impl/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ crate-type = ["lib"]
1616
bench = false
1717

1818
[dependencies]
19+
bytes = "1"
20+
http = "1"
1921
libdd-capabilities = { path = "../libdd-capabilities", version = "0.1.0" }
2022
libdd-common = { path = "../libdd-common", version = "3.0.2" }

libdd-capabilities-impl/src/lib.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,40 @@
99
1010
mod http;
1111

12+
use core::future::Future;
13+
1214
pub use http::DefaultHttpClient;
15+
use libdd_capabilities::http::HttpError;
1316
pub use libdd_capabilities::HttpClientTrait;
17+
use libdd_capabilities::MaybeSend;
1418

1519
/// Bundle struct for native platform capabilities.
1620
///
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.
2025
///
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

Comments
 (0)