-
Notifications
You must be signed in to change notification settings - Fork 136
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
Add with_callback that take a Fn taking request and returning responses #459
Conversation
Thanks for putting this up, it should be useful to check if this satisfies some of the many use-cases previously posted. I agree an Appreciate it if someone in the community has any further insight. |
I have a working version and an example use case which mod the request. I'll update this branch soon |
13ca514
to
6be8f67
Compare
74de03c
to
343811f
Compare
Edit: It works and the doctest passes. Should be good to merge |
d2c36fe
to
4de12da
Compare
This looks great, I'm going to ask the others who wanted this to see if they need anything else... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate the work done here! ❤️
I left only one subjective suggestion, if you find it valuable
But in terms of functionality, it seems to cover the needs. Thank you!
Sorry, looks like my suggestion got missed by |
My bad I didn't check before end, also I'm on my work laptop without my github ssh key so I won't be able to fix it soon. Have you tested the doc example? Does it compile? I'm wondering because I tried adding the |
Nevermind it just passed the test :) Thanks for the help :) |
Also I wasn't careful and I commited the generated file |
I'll be able to fix my change in 5hours or so, sorry for the inconveniance |
The callback takes a request and return a response
6b5933d
to
cdc3fe3
Compare
Co-authored-by: Artem Medvedev <[email protected]>
cdc3fe3
to
e1f680d
Compare
c251af6
to
ba2db14
Compare
I cleaned the MR and it passes the doc test now :) |
One last thing, is that using
|
I think |
Yes Re exporting or hiding the type behind an alias solve this problem, the type to define the request will come from bollard crate |
Though that only applies if the user is using a custom request callback, at which point the user may wish to specify her own I'm reading about some conflicting best practices about this when I read about it.. I'm wondering if someone more knowledgeable is available to briefly comment @jonhoo ? 🙏 |
I believe it's a good practice to re-export types (or even whole crate) if it's supposed to be a public interface for the library. In this case
I may want to have closure with explicit types definition (e.g: Another point here - versions should be consistent between client code and For example, that's how |
src/docker.rs
Outdated
/// Callback transport trait | ||
pub trait TransportTrait: Send + Sync { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Callback transport trait | |
pub trait TransportTrait: Send + Sync { | |
/// Callback transport trait | |
pub trait TransportTrait: Send + Sync { |
a nit: I personally find such (pre/post)-fixes excessive, they don't have meaningful part - the type itself defines itself as a trait.
So it's subjective opinion, but CustomTransport
or Transport
should work well. Also callback
in documentation looks a bit unrelated, it's just an interface to pass your custom transport implementation.
It's just implemented for callback too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make the changes
It's not applicable for general usage of the library, outside of the use cases described here and associated tickets.
Maybe I don't understand exactly what you mean, but if http v2 is released, by re-exporting the http crate, the user is forced to use http v1 for the callback handler and he can't actually use http v2 inside bollard. |
No, what I mean is: bollard requires users to use particular version of dependency for this feature while their http dependency might be independent. For example, I have some code in my application which depends on But when types are re-exported, it's responsibility of bollard to update the version, not mine as a client. It's ofc still uses http1 under the hood and you will see this within Cargo.lock, but I don't have to manage this, since it's part of bollard. And what can be useful here for maintenance is that it's more obvious whether a crate update should be considered a breaking change if types are re-exported. Otherwise, it's easier to update a dependency without realizing that some users depend on it.
It's still part of public api, it can be type alias or just re-export through some of modules - but it is, even for some particular use-case. |
OK, let's re-export these public types. I'm not entirely convinced ... but happy to defer to someone else's wisdom here and do some more reading. |
15f379b
to
009988c
Compare
LGTM |
Thanks for all the great work here! |
#458
This compile but I haven't successfully used it yet.
It takes a Fn but should probably take a FnMut or Stream for more convenience, but I couldn't make it work with RefCell or RWLock.
Any help is appreciated, especially if you known your way around Send + Sync + Async Stream :)