Skip to content

Commit

Permalink
Re-export Request<BodyType> as BollardRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
izissise committed Sep 4, 2024
1 parent ba2db14 commit 009988c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,25 @@ pub(crate) enum ClientType {
},
}

/// `Request` from bollard used with `CustomTransport`
pub type BollardRequest = Request<BodyType>;

type TransportReturnTy =
Pin<Box<dyn Future<Output = Result<Response<hyper::body::Incoming>, Error>> + Send>>;

/// Callback transport trait
pub trait TransportTrait: Send + Sync {
/// `CustomTransport` trait
pub trait CustomTransport: Send + Sync {
/// Make a request, this returns a future
fn request(&self, request: Request<BodyType>) -> TransportReturnTy;
fn request(&self, request: BollardRequest) -> TransportReturnTy;
}

// auto impl for Fn(Request) -> Future<Output = Result<_, _>
impl<Callback, ReturnTy> TransportTrait for Callback
impl<Callback, ReturnTy> CustomTransport for Callback
where
Callback: Fn(Request<BodyType>) -> ReturnTy + Send + Sync,
Callback: Fn(BollardRequest) -> ReturnTy + Send + Sync,
ReturnTy: Future<Output = Result<Response<hyper::body::Incoming>, Error>> + Send + 'static,
{
fn request(&self, request: Request<BodyType>) -> TransportReturnTy {
fn request(&self, request: BollardRequest) -> TransportReturnTy {
Box::pin(self(request))
}
}
Expand Down Expand Up @@ -141,7 +144,7 @@ pub(crate) enum Transport {
client: Client<yup_hyper_mock::HostToReplyConnector, BodyType>,
},
Custom {
transport: Box<dyn TransportTrait>,
transport: Box<dyn CustomTransport>,
},
}

Expand Down Expand Up @@ -628,8 +631,7 @@ impl Docker {
/// # Examples
///
/// ```rust,no_run
/// use bollard::{API_DEFAULT_VERSION, Docker, BodyType};
/// use hyper::Request;
/// use bollard::{API_DEFAULT_VERSION, Docker, BollardRequest};
/// use futures_util::future::TryFutureExt;
/// use futures_util::FutureExt;
Expand All @@ -641,7 +643,7 @@ impl Docker {
/// let client = std::sync::Arc::new(client_builder.build(http_connector));
///
/// let connection = Docker::connect_with_custom_transport(
/// move |req: Request<BodyType>| {
/// move |req: BollardRequest| {
/// let client = std::sync::Arc::clone(&client);
/// Box::pin(async move {
/// let (p, b) = req.into_parts();
Expand All @@ -651,7 +653,7 @@ impl Docker {
/// // uri::PathAndQuery::try_from("/docker".to_owned() + paq.as_str())
/// // ).transpose().map_err(bollard::errors::Error::from)?;
/// // p.uri = uri.try_into().map_err(bollard::errors::Error::from)?;
/// let req = Request::<BodyType>::from_parts(p, b);
/// let req = BollardRequest::from_parts(p, b);
/// client.request(req).await.map_err(bollard::errors::Error::from)
/// })
/// },
Expand All @@ -664,7 +666,7 @@ impl Docker {
/// .map_ok(|_| Ok::<_, ()>(println!("Connected!")));
/// ```
pub fn connect_with_custom_transport<S: Into<String>>(
transport: impl TransportTrait + 'static,
transport: impl CustomTransport + 'static,
client_addr: Option<S>,
timeout: u64,
client_version: &ClientVersion,
Expand Down Expand Up @@ -1424,7 +1426,7 @@ impl Docker {
}

/// Either a stream or a full response
pub type BodyType = http_body_util::Either<
pub(crate) type BodyType = http_body_util::Either<
Full<Bytes>,
StreamBody<Pin<Box<dyn Stream<Item = Result<Frame<Bytes>, Infallible>> + Send>>>,
>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub mod volume;
pub mod grpc;

// publicly re-export
pub use crate::docker::{BodyType, ClientVersion, Docker, API_DEFAULT_VERSION};
pub use crate::docker::{BollardRequest, ClientVersion, Docker, API_DEFAULT_VERSION};
pub use bollard_stubs::models;

#[cfg(feature = "buildkit")]
Expand Down

0 comments on commit 009988c

Please sign in to comment.