-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat: update to tokio 0.2 and futures 0.3 #134
Conversation
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.
Thank you for your pull requests, @sopium! This looks really good. I've left a few comments with questions and suggestions.
I'd like to hold off on merging this until everything has become stable.
@hawkw This concerns stuff you've worked on before, and you probably know a lot more about futures/tokio/async than I do. Want to take a look?
Cargo.toml
Outdated
libc = "0.2" | ||
mio = { version = "0.6", optional = true } | ||
tokio-io = { version = "=0.2.0-alpha.4", optional = true } | ||
tokio-net = { version = "=0.2.0-alpha.4", optional = true, default-features = false } |
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.
Some of the versions are pinned to an exact alpha version. Is there a specific reason for that?
I think requiring an exact version should usually be avoided, as that can cause problems with other crates that might have slightly different version requirements.
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.
These crates might have breaking changes between different alpha versions, so they are pinned to a specific version. It won't be necessary once they are stable.
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.
Makes sense.
Cargo.toml
Outdated
tempdir = "0.3" | ||
tempdir = "0.3" | ||
futures-util-preview = "=0.3.0-alpha.18" | ||
tokio = "=0.2.0-alpha.4" |
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.
Same as above. Versions are pinned.
src/inotify.rs
Outdated
@@ -405,7 +405,7 @@ impl Inotify { | |||
pub fn event_stream<T>(&mut self, buffer: T) | |||
-> EventStream<T> | |||
where | |||
T: AsMut<[u8]> + AsRef<[u8]>, | |||
T: AsMut<[u8]> + AsRef<[u8]> + Unpin, |
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'm a bit concerned about the Unpin
, as it makes the API less flexible. I think right now one can pass an array, but with the Unpin
, you'd either need a slice (possibly causing lifetime issues) or a heap allocation.
I'm not sure if it can be avoided and if that's a big deal in practice. I just figured I'd point out my concerns, in case you have something informative to say :-)
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.
Arrays are Unpin
. But your general point is valid.
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.
Interesting, I didn't think they were!
src/inotify.rs
Outdated
@@ -422,7 +422,7 @@ impl Inotify { | |||
pub fn event_stream_with_handle<T>(&mut self, handle: &Handle, buffer: T) | |||
-> io::Result<EventStream<T>> | |||
where | |||
T: AsMut<[u8]> + AsRef<[u8]>, | |||
T: AsMut<[u8]> + AsRef<[u8]> + Unpin, |
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.
See comment above about Unpin
.
src/stream.rs
Outdated
@@ -47,7 +39,7 @@ pub struct EventStream<T> { | |||
|
|||
impl<T> EventStream<T> | |||
where | |||
T: AsMut<[u8]> + AsRef<[u8]>, | |||
T: AsMut<[u8]> + AsRef<[u8]> + Unpin, |
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.
See comment above about Unpin
.
src/stream.rs
Outdated
@@ -78,36 +70,37 @@ where | |||
|
|||
impl<T> Stream for EventStream<T> | |||
where | |||
T: AsMut<[u8]> + AsRef<[u8]>, | |||
T: AsMut<[u8]> + AsRef<[u8]> + Unpin, |
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.
See comment above about Unpin
.
src/stream.rs
Outdated
{ | ||
if self.unused_bytes == 0 { | ||
let self_ = self.get_mut(); |
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.
Can we use get_unchecked_mut
here, to forgo the requirement for Unpin
? I don't think we're moving out of self_
, so it should be fine, I think.
Two more things:
|
Thanks for the change, @sopium! Let's hope things become stable soon, so we can merge this. Until then, more reviews/comments are always welcome. |
Any updates on this? Waiting for merge! Maybe this could become available as pre-release? |
@peku33 My understanding is, that this still requires nightly. I don't want to merge it as long as this is the case, as I want the master branch to always be in a releasable state (if someone submits a bugfix, for example). Would it be practical for you to use a Git dependency in Cargo, to depend on @sopium's branch directly? |
@hannobraun How about doing the same as tokio itself did? |
Because that would take time to do and I don't have much of that. From my perspective, it's a much more economical decision to just wait until everything is stable, then merge and release. |
Hmm, pretty sad, especially taking into account fact, that lots of popular crates uses such approach (tokio itself, mysql_async etc). @hannobraun Are you sure accepting @sopium PR with version set to |
@sopium Any way to use event_stream with buffer larger than 32 bytes? For now it looks like |
You can use struct LargeU8Array([u8; 512]);
impl AsRef<[u8]> for LargeU8Array {...}
impl AsMut<[u8]> for LargeU8Array {...} |
I guess those crates have less busy maintainers then, because yes, I am sure that adding yet another thing to my plate would be too much. You haven't commented on my suggestion to add a Git dependency on @sopium's branch in Cargo. Doing so would require no additional work from anyone. If that's not good enough for some reason (the only one I can think of would be that you want to publish a crate with that dependency to crates.io), you can publish your own version of inotify. Call it |
The latest commit is in sync with tokio master. In tokio master, If you are still using |
|
Updated to tokio v0.2.1. The |
Thank you @sopium for your continued work on this! The changes look good to me, but for some reason, the CI build doesn't run. I've set up GitHub Actions instead. Can you please rebase on master, so it runs for this pull request? |
`EventStream` is now a futures 0.3 stream (backed by tokio 0.2) and can be used with async/await. The stream example is updated accordingly. The crate is updated to the 2018 edition, so that related tests and examples can be written in async/await. The CI config is modified to: * Run on nightly * Run with `--no-default-features` as well
tokio 0.2.0-alpha.6 futures 0.3.0-alpha.19
3027d92
to
60dcd82
Compare
Thank you, @sopium! I'll try to release a new version soon. |
(Stability note: this feature depends on nightly rust and alpha releases of tokio 0.2 and futures 0.3. Maybe you want to hold off the merge until they are stable. In which case I will try to make sure that this PR is up to date.)
This is a minimal and straightforward update to make inotify up to date with
std::task
, async-await syntax and next versions of tokio and futures.API changes
EventStream
is now a futures 0.3Stream
A futures 0.3
Stream
can be used with async-await directly (cc Async/Await syntax support #121). See the stream example.The buffer passed to the
event_stream
method is now required to beUnpin
Other changes
Mandatory dependencies is minimized: only
tokio-net
,tokio-io
andfutures-core
are mandatory dependencies. And fortokio-net
unused features are disabled. The fulltokio
crate andfutures-util
are dev-dependencies.The crate is updated to 2018 edition, so that related tests and
examples can be written in async/await.
The CI config is modified to:
--no-default-features
as well