Skip to content
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

Provide support for boxed custom matchers in layer enums #92

Closed
GlenDC opened this issue Mar 15, 2024 · 7 comments · Fixed by #140
Closed

Provide support for boxed custom matchers in layer enums #92

GlenDC opened this issue Mar 15, 2024 · 7 comments · Fixed by #140
Assignees
Labels
easy An easy issue to pick up for anyone. good first issue Good for newcomers mentor available A mentor is available to help you through the issue.
Milestone

Comments

@GlenDC
Copy link
Member

GlenDC commented Mar 15, 2024

For both stream (L4) and http layers we have enums to allow for single type groupings. As an escape hatch might be good to allow custom boxed variants as well.

@GlenDC GlenDC added good first issue Good for newcomers easy An easy issue to pick up for anyone. labels Mar 15, 2024
@GlenDC GlenDC added this to the v0.2 milestone Mar 15, 2024
@GlenDC GlenDC added the mentor available A mentor is available to help you through the issue. label Mar 15, 2024
@dmackdev
Copy link
Contributor

Hi @GlenDC, could you please provide some guidance for the type of the inner field of the new enum variant?

Should we use the Matcher trait, so something like:

pub enum HttpMatcherKind
    //...
    Predicate(Arc<dyn crate::service::Matcher<State, Request<Body>>>)
}

Or the Fn trait, similar to how it is done in the http::layer::cors module, e.g. here? Would this need as arguments all the arguments in the Matcher::matches trait method, or just the Request?

Is it correct that this change will require introducing generics for HttpMatcherKind and HttpMatcher, in order for the Body parameter to align with their Matcher trait implementations?

@GlenDC
Copy link
Member Author

GlenDC commented Mar 30, 2024

I would do it like this:

pub enum HttpMatcherKind<State, Body> {
    //...
    Custom(Box<dyn crate::service::Matcher<State, Request<Body>>>)
}

So a Box instead of an Arc, and I would call it Custom or something like that.

It does indeed also mean that you'll need to introduce generic parameters, not much that can be done about that.
Let me know if introducing that gives difficulties in some use cases @dmackdev , we can always give this some more thought if it does. I think it should be okay as those parameters should be able to be inferred in any use case I can think of, e.g. it's not much different of how many Services require this knowledge as well.

Other then that you're good to go. Thanks again.

@dmackdev
Copy link
Contributor

dmackdev commented Mar 31, 2024

I've attempted to add the Custom variant in this PR: dmackdev#1.
I have branched off of https://github.com/dmackdev/rama/tree/add-http-matcher-methods.
But I am running into some issues - I have left some comments on that PR. Would appreciate some guidance @GlenDC.

@GlenDC
Copy link
Member Author

GlenDC commented Mar 31, 2024

I've attempted to add the Custom variant in this PR: dmackdev#1. I have branched off of https://github.com/dmackdev/rama/tree/add-http-matcher-methods. But I am running into some issues - I have left some comments on that PR. Would appreciate some guidance @GlenDC.

Awesome work @dmackdev . Seeing the progress makes me happy. I left comments and a review behind on your pull request. I hope this serves as sufficient guidance. But if something is still not clear, or you want to spar some ideas or other feedback, do let me know. All good.

@GlenDC
Copy link
Member Author

GlenDC commented Apr 3, 2024

The work for the Http layer has been completed by @dmackdev for this story.

@dmackdev do you also want to tackle the same work but for the transport layer, or do you prefer to pass that to someone else? Up to you!

@dmackdev
Copy link
Contributor

dmackdev commented Apr 4, 2024

@GlenDC I can pick this up for the transport layer too.

@GlenDC
Copy link
Member Author

GlenDC commented Apr 4, 2024

Great! All yours and thank you for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy An easy issue to pick up for anyone. good first issue Good for newcomers mentor available A mentor is available to help you through the issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants