-
Notifications
You must be signed in to change notification settings - Fork 96
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
Filenames now must allow references to Path
#230
Conversation
In general, my preference is to split the non-generic parts of those functions like in https://doc.rust-lang.org/src/std/fs.rs.html#928-930. But I suppose you could argue that most of these functions are relatively small, so I don't have a strong opinion on this. PS: I haven't looked too close otherwise. |
What is the reason or advantage for doing this? I guess it could be an improvement if we call the method internally lots of times and save some |
Non-generic code is compiled in the crate where it's defined. Generic code is compiled in the crate where it's used, possibly multiple times (either with different generic arguments or if it's used from multiple functions and they end up in different CGUs). This is similar to This is fine for something like But as I said, it probably doesn't matter too much here. |
Okay, I didn't have that in mind. But still, you wouldn't change it for this PR? |
Sorry for taking so long to review this. I think at least But if I was doing this, I'd probably split everything except |
src/dataset.rs
Outdated
filename: P, | ||
options: &[RasterCreationOption], | ||
) -> Result<Dataset> { | ||
Self::_create_copy(&self, driver, filename.as_ref(), options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self::_create_copy(&self, driver, filename.as_ref(), options) | |
self._create_copy(driver, filename.as_ref(), options) |
src/driver.rs
Outdated
@@ -130,7 +148,11 @@ impl Driver { | |||
/// | |||
/// Calls `GDALDeleteDataset()` | |||
/// | |||
pub fn delete(&self, filename: &Path) -> Result<()> { | |||
pub fn delete<P: AsRef<Path>>(&self, filename: P) -> Result<()> { | |||
Self::_delete(&self, filename.as_ref()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self::_delete(&self, filename.as_ref()) | |
self._delete(filename.as_ref()) |
src/driver.rs
Outdated
new_filename: P1, | ||
old_filename: P2, | ||
) -> Result<()> { | ||
Self::_rename(&self, new_filename.as_ref(), old_filename.as_ref()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self::_rename(&self, new_filename.as_ref(), old_filename.as_ref()) | |
self._rename(new_filename.as_ref(), old_filename.as_ref()) |
src/vsi.rs
Outdated
} | ||
|
||
fn _create_mem_file_from_ref<'d>(file_name: &Path, data: &'d mut [u8]) -> Result<MemFileRef<'d>> { | ||
let file_name_c = _path_to_c_string(&file_name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let file_name_c = _path_to_c_string(&file_name)?; | |
let file_name_c = _path_to_c_string(file_name)?; |
src/vsi.rs
Outdated
} | ||
|
||
fn _unlink_mem_file(file_name: &Path) -> Result<()> { | ||
let file_name_c = _path_to_c_string(&file_name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let file_name_c = _path_to_c_string(&file_name)?; | |
let file_name_c = _path_to_c_string(file_name)?; |
src/driver.rs
Outdated
Self::_create_with_band_type_with_options::<T>( | ||
&self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self::_create_with_band_type_with_options::<T>( | |
&self, | |
self._create_with_band_type_with_options::<T>( |
Some clippy lints, but it looks all right. I'll merge it tomorrow unless anyone else objects. |
Great! thanks fr reviewing @lnicola . i can create a new release in the next days :) |
I had an old Rust version installed since we use a toolchain file for Geo Engine 😄. But I've fixed them in |
"Tomorrow" bors r+ |
Build succeeded: |
CHANGES.md
if knowledge of this change could be valuable to users.According to affirmation in #227 I changed all file paths to be implementing
AsRef<Path>
.This is based on @lnicola's idea and is similar to https://doc.rust-lang.org/std/fs/struct.File.html#method.open.
This introduced generics on the methods but I guess less code-breaking since you can still input
&str
s.