pub fn from_readonly_file<FD: AsRawFd>(fd: FD, len: usize) -> io::Result<Self> {
        // mmap fails on 0-size requests, which is extremely annoying in
        // practice, so we construct a bogus 0-sized mapping instead.
        if len == 0 {
            return Ok(Self {
                addr: std::ptr::null_mut(),
                len,
            });
        }

        // It's not clear why mmap-ing a file is considered unsafe.  Using the
        // address is indeed unsafe, but mmap itself doesn't do anything bad.
        let addr = unsafe {
            mmap(
                std::ptr::null_mut(),
                len,
                ProtFlags::PROT_READ,
                MapFlags::MAP_SHARED,
                fd.as_raw_fd(),
                /* offset = */ 0,
            )
        }
        .map_err(nix_to_io_err)?;
        Ok(Self { addr, len })
    }
/// Creates a new mapping from a file descriptor and length.
Creates a new mapping from a file descriptor and length.
Creates a new mapping from a file descriptor and length .
pub fn from_readonly_file<FD: AsRawFd>(fd: FD, len: usize) -> io::Result<Self> {
        // mmap fails on 0-size requests, which is extremely annoying in
        // practice, so we construct a bogus 0-sized mapping instead.
        if len == 0 {
            return Ok(Self {
                addr: std::ptr::null_mut(),
                len,
            });
        }
        // It's not clear why mmap-ing a file is considered unsafe.  Using the
        // address is indeed unsafe, but mmap itself doesn't do anything bad.
        let addr = unsafe {
            mmap(
                std::ptr::null_mut(),
                len,
                ProtFlags::PROT_READ,
                MapFlags::MAP_SHARED,
                fd.as_raw_fd(),
                /* offset = */ 0,
            )
        }
        .map_err(nix_to_io_err)?;
        Ok(Self { addr, len })
    }
pub fn from_readonly_file < FD : AsRawFd > ( fd : FD , len : usize ) -> io :: Result < Self > { // mmap fails on 0-size requests, which is extremely annoying in // practice, so we construct a bogus 0-sized mapping instead. if len == 0 { return Ok ( Self { addr : std :: ptr :: null_mut ( ) , len , } ) ; } // It's not clear why mmap-ing a file is considered unsafe.  Using the // address is indeed unsafe, but mmap itself doesn't do anything bad. let addr = unsafe { mmap ( std :: ptr :: null_mut ( ) , len , ProtFlags :: PROT_READ , MapFlags :: MAP_SHARED , fd . as_raw_fd ( ) , /* offset = */ 0 , ) } . map_err ( nix_to_io_err ) ? ; Ok ( Self { addr , len } ) }
Creates a new mapping from a file descriptor and length.
Creates a new mapping from a file descriptor and length .
fd
FD
len
usize
fd
FD
len
usize