Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feature: Middleware Architecture #65

Merged
merged 15 commits into from
Sep 24, 2020
Merged

feature: Middleware Architecture #65

merged 15 commits into from
Sep 24, 2020

Conversation

gakonst
Copy link
Owner

@gakonst gakonst commented Sep 17, 2020

Introduces a new Middleware trait which is implemented by Provider. Anyone that writes a new middleware needs to implement it, like below:

struct MyStruct<M>(M);

#[derive(Error, Debug)]
pub enum MyError<M: Middleware> {
    #[error("{0}")]
    MiddlewareError(M::Error),

    // Add your middleware's specific errors here
}

#[async_trait(?Send)]
impl<M> Middleware for MyStruct<M>
where
    M: Middleware,
{
    type Error = MyError<M>;
    type Provider = M::Provider;
    type Inner = M;

    fn inner(&self) -> &M {
        &self.0
    }
 
   // Add any of the functions you want to override e.g. a logging middleware
}

@gakonst gakonst marked this pull request as ready for review September 24, 2020 13:46
@gakonst gakonst changed the title try moving methods to a middleware trait feature: Middleware Architecture Sep 24, 2020
@gakonst gakonst merged commit 2d51c52 into master Sep 24, 2020
@gakonst gakonst deleted the middleware branch September 24, 2020 21:33
meetmangukiya pushed a commit to meetmangukiya/ethers-rs that referenced this pull request Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants