diff --git a/src/file.rs b/src/file.rs index c740627..bee7520 100644 --- a/src/file.rs +++ b/src/file.rs @@ -45,12 +45,8 @@ impl std::ops::DerefMut for File { impl File { /// Open a netCDF file in read only mode. - pub fn open

(file: P) -> error::Result - where - P: AsRef, - { - let data_path = file.as_ref(); - let f = CString::new(data_path.to_str().unwrap()).unwrap(); + pub fn open(path: &path::Path) -> error::Result { + let f = CString::new(path.to_str().unwrap()).unwrap(); let mut ncid: nc_type = -1; let err: nc_type; unsafe { @@ -65,18 +61,14 @@ impl File { Ok(File { ncid, - name: data_path.file_name().unwrap().to_string_lossy().to_string(), + name: path.file_name().unwrap().to_string_lossy().to_string(), root, }) } /// Open a netCDF file in append mode (read/write). /// The file must already exist. - pub fn append

(file: P) -> error::Result - where - P: AsRef, - { - let data_path = file.as_ref(); - let f = CString::new(data_path.to_str().unwrap()).unwrap(); + pub fn append(path: &path::Path) -> error::Result { + let f = CString::new(path.to_str().unwrap()).unwrap(); let mut ncid: nc_type = -1; let err: nc_type; unsafe { @@ -91,17 +83,13 @@ impl File { Ok(File { ncid, - name: data_path.file_name().unwrap().to_string_lossy().to_string(), + name: path.file_name().unwrap().to_string_lossy().to_string(), root, }) } /// Open a netCDF file in creation mode (write only). - pub fn create

(file: P) -> error::Result - where - P: AsRef, - { - let data_path = file.as_ref(); - let f = CString::new(data_path.to_str().unwrap()).unwrap(); + pub fn create(path: &path::Path) -> error::Result { + let f = CString::new(path.to_str().unwrap()).unwrap(); let mut ncid: nc_type = -1; let err: nc_type; unsafe { @@ -123,7 +111,7 @@ impl File { }; Ok(File { ncid, - name: data_path.file_name().unwrap().to_string_lossy().to_string(), + name: path.file_name().unwrap().to_string_lossy().to_string(), root, }) } diff --git a/src/lib.rs b/src/lib.rs index f9710f9..5967007 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ pub fn create

(name: P) -> error::Result where P: AsRef, { - File::create(name) + File::create(name.as_ref()) } /// Open a netcdf file in append mode @@ -91,7 +91,7 @@ pub fn append

(name: P) -> error::Result where P: AsRef, { - File::append(name) + File::append(name.as_ref()) } /// Open a netcdf file in read mode @@ -99,7 +99,7 @@ pub fn open

(name: P) -> error::Result where P: AsRef, { - File::open(name) + File::open(name.as_ref()) } #[cfg(feature = "memory")] diff --git a/tests/lib.rs b/tests/lib.rs index 73dbdac..e285648 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -13,7 +13,7 @@ fn test_location() -> std::path::PathBuf { fn use_path_to_open() { let path = test_location().join("simple_xy.nc"); - let _file = netcdf::File::open(path).unwrap(); + let _file = netcdf::open(path).unwrap(); } #[test] @@ -31,7 +31,7 @@ fn use_string_to_open() { #[test] fn bad_filename() { let f = test_location().join("blah_stuff.nc"); - let res_file = netcdf::File::open(&f); + let res_file = netcdf::open(&f); assert_eq!(res_file.unwrap_err(), netcdf::error::Error::Netcdf(2)); } @@ -195,7 +195,7 @@ fn nc4_groups() { fn create_group_dimensions() { let d = tempfile::tempdir().unwrap(); let filepath = d.path().join("create_group.nc"); - let mut f = netcdf::File::create(filepath).unwrap(); + let mut f = netcdf::create(filepath).unwrap(); f.add_dimension("x", 20).unwrap(); @@ -417,7 +417,7 @@ fn all_var_types() { { // read let f = d.path().join(name); - let file = netcdf::File::open(f).unwrap(); + let file = netcdf::open(f).unwrap(); //byte let mut data = vec![0i8; 10];