mirror of
https://github.com/georust/netcdf.git
synced 2025-12-08 19:25:14 +00:00
restrict generics to entrypoint
This commit is contained in:
parent
e4b05021a6
commit
568b2ce4f8
30
src/file.rs
30
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<P>(file: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<path::Path>,
|
||||
{
|
||||
let data_path = file.as_ref();
|
||||
let f = CString::new(data_path.to_str().unwrap()).unwrap();
|
||||
pub fn open(path: &path::Path) -> error::Result<File> {
|
||||
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<P>(file: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<path::Path>,
|
||||
{
|
||||
let data_path = file.as_ref();
|
||||
let f = CString::new(data_path.to_str().unwrap()).unwrap();
|
||||
pub fn append(path: &path::Path) -> error::Result<File> {
|
||||
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<P>(file: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<path::Path>,
|
||||
{
|
||||
let data_path = file.as_ref();
|
||||
let f = CString::new(data_path.to_str().unwrap()).unwrap();
|
||||
pub fn create(path: &path::Path) -> error::Result<File> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ pub fn create<P>(name: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<std::path::Path>,
|
||||
{
|
||||
File::create(name)
|
||||
File::create(name.as_ref())
|
||||
}
|
||||
|
||||
/// Open a netcdf file in append mode
|
||||
@ -91,7 +91,7 @@ pub fn append<P>(name: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<std::path::Path>,
|
||||
{
|
||||
File::append(name)
|
||||
File::append(name.as_ref())
|
||||
}
|
||||
|
||||
/// Open a netcdf file in read mode
|
||||
@ -99,7 +99,7 @@ pub fn open<P>(name: P) -> error::Result<File>
|
||||
where
|
||||
P: AsRef<std::path::Path>,
|
||||
{
|
||||
File::open(name)
|
||||
File::open(name.as_ref())
|
||||
}
|
||||
|
||||
#[cfg(feature = "memory")]
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user