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

Filenames now must allow references to Path #230

Merged
merged 4 commits into from
Nov 5, 2021

Conversation

ChristianBeilschmidt
Copy link
Contributor

@ChristianBeilschmidt ChristianBeilschmidt commented Oct 26, 2021

  • I agree to follow the project's code of conduct.
  • I added an entry to 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 &strs.

@lnicola
Copy link
Member

lnicola commented Oct 26, 2021

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.

@ChristianBeilschmidt
Copy link
Contributor Author

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 as_ref calls but I doubt that this is the case.

@lnicola
Copy link
Member

lnicola commented Oct 27, 2021

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 #[inline], except that it doesn't get inlined.

This is fine for something like Vec<T> where you want the best codegen possible (even there only the size of T matters if it has a trivial Drop), but a large function with a path.as_ref() at the beginning is the worst case possible because it makes the whole thing generic.

But as I said, it probably doesn't matter too much here.

@ChristianBeilschmidt
Copy link
Contributor Author

Okay, I didn't have that in mind. But still, you wouldn't change it for this PR?

@lnicola
Copy link
Member

lnicola commented Nov 2, 2021

Sorry for taking so long to review this. I think at least Dataset::open_ex, Dataset::create_copy and Driver::create_with_band_type_with_options are large enough to warrant splitting.

But if I was doing this, I'd probably split everything except Dataset::open and Driver::create_with_band_type.

src/dataset.rs Outdated
filename: P,
options: &[RasterCreationOption],
) -> Result<Dataset> {
Self::_create_copy(&self, driver, filename.as_ref(), options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let file_name_c = _path_to_c_string(&file_name)?;
let file_name_c = _path_to_c_string(file_name)?;

src/driver.rs Outdated
Comment on lines 98 to 99
Self::_create_with_band_type_with_options::<T>(
&self,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Self::_create_with_band_type_with_options::<T>(
&self,
self._create_with_band_type_with_options::<T>(

@lnicola
Copy link
Member

lnicola commented Nov 3, 2021

Some clippy lints, but it looks all right. I'll merge it tomorrow unless anyone else objects.

@jdroenner
Copy link
Member

Great! thanks fr reviewing @lnicola . i can create a new release in the next days :)

@ChristianBeilschmidt
Copy link
Contributor Author

Some clippy lints, but it looks all right. I'll merge it tomorrow unless anyone else objects.

I had an old Rust version installed since we use a toolchain file for Geo Engine 😄. But I've fixed them in
4d4e040 .

@lnicola
Copy link
Member

lnicola commented Nov 5, 2021

"Tomorrow"

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 5, 2021

@bors bors bot merged commit 041a570 into georust:master Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants