Skip to content

Commit

Permalink
Merge pull request #21 from Mrmaxmeier/fix-stub
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon authored Aug 5, 2021
2 parents 1737816 + 651ef08 commit 2406f2f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
check:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: cargo test

test-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
target:
Expand All @@ -84,8 +84,29 @@ jobs:
- name: Run tests
run: cargo test

check-stub:
runs-on: ubuntu-20.04
strategy:
matrix:
target:
- wasm32-unknown-unknown
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
override: true

- name: Run check
run: cargo check --all-targets --target ${{ matrix.target }}

test-msrv:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::unix::MmapInner;
#[cfg(not(any(unix, windows)))]
mod stub;
#[cfg(not(any(unix, windows)))]
use crate::stub::file_len;
#[cfg(not(any(unix, windows)))]
use crate::stub::MmapInner;

use std::fmt;
Expand All @@ -36,6 +38,9 @@ pub struct MmapRawDescriptor<'a>(&'a File);
#[cfg(unix)]
pub struct MmapRawDescriptor(std::os::unix::io::RawFd);

#[cfg(not(any(unix, windows)))]
pub struct MmapRawDescriptor<'a>(&'a File);

pub trait MmapAsRawDesc {
fn as_raw_desc(&self) -> MmapRawDescriptor;
}
Expand All @@ -61,6 +66,13 @@ impl MmapAsRawDesc for std::os::unix::io::RawFd {
}
}

#[cfg(not(any(unix, windows)))]
impl MmapAsRawDesc for &File {
fn as_raw_desc(&self) -> MmapRawDescriptor {
MmapRawDescriptor(self)
}
}

/// A memory map builder, providing advanced options and flags for specifying memory map behavior.
///
/// `MmapOptions` can be used to create an anonymous memory map using [`map_anon()`], or a
Expand Down
14 changes: 9 additions & 5 deletions src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ impl MmapInner {
))
}

pub fn map(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_exec(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_exec(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_mut(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_mut(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy_read_only(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy_read_only(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

Expand Down Expand Up @@ -74,3 +74,7 @@ impl MmapInner {
unreachable!("self unconstructable");
}
}

pub fn file_len(file: &File) -> io::Result<usize> {
Ok(file.metadata()?.len() as usize)
}

0 comments on commit 2406f2f

Please sign in to comment.