nanocodex_service/
client.rs1use tower::{Service, ServiceExt};
2
3use crate::attempt::ResponsesAttempt;
4
5pub struct ResponsesClient<S> {
7 service: S,
8}
9
10impl<S> ResponsesClient<S> {
11 pub const fn new(service: S) -> Self {
12 Self { service }
13 }
14
15 pub const fn service(&self) -> &S {
16 &self.service
17 }
18
19 pub const fn service_mut(&mut self) -> &mut S {
20 &mut self.service
21 }
22
23 pub fn into_service(self) -> S {
24 self.service
25 }
26
27 #[must_use]
28 pub fn map_service<T>(self, map: impl FnOnce(S) -> T) -> ResponsesClient<T> {
29 ResponsesClient::new(map(self.service))
30 }
31
32 pub async fn execute(&mut self, request: ResponsesAttempt) -> Result<S::Response, S::Error>
38 where
39 S: Service<ResponsesAttempt>,
40 {
41 self.service.ready().await?.call(request).await
42 }
43}