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

Implementing support for async_std types #26

Closed
wants to merge 3 commits into from

Conversation

gabrik
Copy link

@gabrik gabrik commented Sep 16, 2021

This PR contains the code for supporting async_std types in MmapOptions.

The async_std support is gated using a feature.
If someone wants to use this feature has to enable it in their Cargo.toml

eg.

memmap2 = {version = "0.3.1", features = ["async"] }

I tested it on this crate: https://github.com/atolab/zenoh-cdn/tree/feat/all-async

I had no possibility yet to test it on a Windows machine

Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@RazrFalcon
Copy link
Owner

Can you also write tests? I guess they should be implemented as a separate crate or example or something. I'm not familiar with async at all.

@gabrik gabrik marked this pull request as draft September 17, 2021 07:12
Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
@gabrik gabrik marked this pull request as ready for review September 17, 2021 13:28

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[lib]
doctest = false
Copy link
Author

@gabrik gabrik Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to avoid testing the documentation examples.
When testing the async feature the documentation examples fail, this is why I disabled it.

@RazrFalcon
Copy link
Owner

CI fails.

@adamreichold
Copy link

adamreichold commented Sep 19, 2021

Is it really necessary to special case this for the types from async_std? Can't this be achieved by going through raw file descriptors resp. handles without direct coupling between the crates?

Related to that, the use of the feature does seem problematic, e.g.

#[cfg(feature = "async")]
#[cfg(windows)]
pub struct MmapRawDescriptor(async_std::os::windows::io::RawHandle);

#[cfg(not(feature = "async"))]
#[cfg(windows)]
pub struct MmapRawDescriptor<'a>(&'a File);

seems to imply that if any crate in the dependency tree enables the async feature, this crate will loose its support for std::fs::File? What if there are users of this crate which depend on the std-based API? Features should generally be additive, i.e. in this case add implementations of MmapAsRawDesc but not remove them.

@RazrFalcon
Copy link
Owner

Agree. I would prefer the integration of this feature to be more simple.

@RazrFalcon
Copy link
Owner

Superseded by #31

@RazrFalcon RazrFalcon closed this Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants