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

Extend MmapAsRawDesc to handle anything implementing AsRawFd #30

Merged
merged 1 commit into from
Sep 19, 2021
Merged

Extend MmapAsRawDesc to handle anything implementing AsRawFd #30

merged 1 commit into from
Sep 19, 2021

Conversation

adamreichold
Copy link

@adamreichold adamreichold commented Sep 19, 2021

This automatically extends support to e.g. async-std. For example, the following variant on its cat example works

use std::env::args;

use async_std::fs::File;
use async_std::io;
use async_std::prelude::*;
use async_std::task;

use memmap2::Mmap;

fn main() -> io::Result<()> {
    let path = args().nth(1).expect("missing path argument");

    task::block_on(async {
        let file = File::open(&path).await?;
        let map = unsafe { Mmap::map(&file)? };

        let mut stdout = io::stdout();
        stdout.write_all(&map).await?;
        stdout.flush().await?;

        Ok(())
    })
}

@adamreichold
Copy link
Author

I am looking into doing the same for Windows, i.e. going for

#[cfg(windows)]
pub struct MmapRawDescriptor(RawHandle);

even though it will mean breaking this up against #[cfg(not(any(unix, windows)))] again. Sorry for the back and forth... |-\

@RazrFalcon
Copy link
Owner

RazrFalcon commented Sep 19, 2021

Sure, no problem. I like those patches.

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.

2 participants