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

Fix has-mmap flag for netcdf crate #126

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netcdf/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
if std::env::var("DEP_NETCDF_SYS_HAS_MMAP").is_ok() {
if std::env::var("DEP_NETCDF_HAS_MMAP").is_ok() {
println!("cargo:rustc-cfg=feature=\"has-mmap\"");
}
}
14 changes: 7 additions & 7 deletions netcdf/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl RawFile {
pub(crate) fn open_from_memory<'buffer>(
name: Option<&str>,
mem: &'buffer [u8],
) -> error::Result<MemFile<'buffer>> {
) -> error::Result<FileMem<'buffer>> {
let cstr = std::ffi::CString::new(name.unwrap_or("/")).unwrap();
let mut ncid = 0;
unsafe {
Expand All @@ -109,13 +109,13 @@ impl RawFile {
cstr.as_ptr(),
NC_NOWRITE,
mem.len(),
mem.as_ptr() as *const u8 as *mut _,
mem.as_ptr().cast_mut().cast(),
&mut ncid,
)
}))?;
}

Ok(MemFile(File(Self { ncid }), PhantomData))
Ok(FileMem(File(Self { ncid }), PhantomData))
}
}

Expand Down Expand Up @@ -425,8 +425,8 @@ impl FileMut {
}

#[cfg(feature = "has-mmap")]
/// The memory mapped file is kept in this structure to keep the
/// lifetime of the buffer longer than the file.
/// The memory mapped file is kept in this structure to extend
/// the lifetime of the buffer.
///
/// Access a [`File`] through the `Deref` trait,
/// ```no_run
Expand All @@ -438,10 +438,10 @@ impl FileMut {
/// # Ok(()) }
/// ```
#[allow(clippy::module_name_repetitions)]
pub struct MemFile<'buffer>(File, std::marker::PhantomData<&'buffer [u8]>);
pub struct FileMem<'buffer>(File, std::marker::PhantomData<&'buffer [u8]>);

#[cfg(feature = "has-mmap")]
impl<'a> std::ops::Deref for MemFile<'a> {
impl<'a> std::ops::Deref for FileMem<'a> {
type Target = File;
fn deref(&self) -> &Self::Target {
&self.0
Expand Down
4 changes: 3 additions & 1 deletion netcdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ pub use attribute::{Attribute, AttributeValue};
pub use dimension::{Dimension, DimensionIdentifier};
pub use error::{Error, Result};
pub use extent::{Extent, Extents};
#[cfg(feature = "has-mmap")]
pub use file::FileMem;
pub(crate) use file::RawFile;
pub use file::{File, FileMut, Options};
pub use group::{Group, GroupMut};
Expand Down Expand Up @@ -174,7 +176,7 @@ where

#[cfg(feature = "has-mmap")]
/// Open a `netCDF` file from a buffer
pub fn open_mem<'a>(name: Option<&str>, mem: &'a [u8]) -> error::Result<MemFile<'a>> {
pub fn open_mem<'a>(name: Option<&str>, mem: &'a [u8]) -> error::Result<FileMem<'a>> {
RawFile::open_from_memory(name, mem)
}

Expand Down