Skip to content

util: add Wrap #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
util: Fix variance on Pre/Post
Also tweak nested type signatures on `Pre`/`Post` to use type parameters
instead of associated types to simplify the rustdoc output.
  • Loading branch information
lilyball committed Jul 11, 2022
commit 7b0d049765af3ef6d88fd2701bea971b5972feba
10 changes: 4 additions & 6 deletions tower/src/util/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ where
#[allow(missing_debug_implementations)]
pub struct Pre<Req, Res, E, F> {
f: F,
_marker: PhantomData<fn(Req) -> (Res, E)>,
_marker: PhantomData<fn(Req) -> (Req, Res, E)>,
}

impl<F, Req, Post, Res, E> PreFn<Req> for Pre<Req, Res, E, F>
Expand All @@ -363,9 +363,7 @@ where
type Value = Post;
type Response = Res;
type Error = E;
type Future = std::future::Ready<
Result<(Self::Request, Self::Value), Result<Self::Response, Self::Error>>,
>;
type Future = std::future::Ready<Result<(Req, Post), Result<Res, E>>>;

fn call(&mut self, request: Req) -> Self::Future {
let f2 = (self.f)(&request);
Expand All @@ -379,7 +377,7 @@ where
/// asynchronous failable post function given to [`Wrap::decorate`].
#[allow(missing_debug_implementations)]
pub struct Post<F, E> {
_marker: PhantomData<fn(F) -> E>,
_marker: PhantomData<fn(F, E) -> E>,
}

impl<F, Res, E, T> PostFn<Res, E, F> for Post<F, E>
Expand All @@ -388,7 +386,7 @@ where
{
type Response = T;
type Error = E;
type Future = std::future::Ready<Result<Self::Response, Self::Error>>;
type Future = std::future::Ready<Result<T, E>>;

fn call(self, result: Result<Res, E>, value: F) -> Self::Future {
std::future::ready(result.map(value))
Expand Down