Skip to content

Added Extend and various FromIterator implementations to CslStringList. - #457

Merged
metasim merged 1 commit into
georust:masterfrom
metasim:feature/csl-extend
Nov 6, 2023
Merged

metasim merged 1 commit into
georust:masterfrom
metasim:feature/csl-extend

Conversation

@metasim

@metasim metasim commented Oct 26, 2023 •

Copy link
Copy Markdown
Contributor
  • 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.

Addresses some leftover feedback from here.

The docs summarize what this PR enables:

image

@metasim
metasim requested review from jdroenner and lnicola October 26, 2023 20:51
@metasim metasim mentioned this pull request Oct 27, 2023
10 tasks done
@metasim

metasim commented Oct 29, 2023

Copy link
Copy Markdown
Contributor Author

@lnicola @jdroenner r+?

@lnicola

lnicola commented Oct 29, 2023

Copy link
Copy Markdown
Member

Sorry, I was away for the past couple of days. I'll take a look tomorrow.

@@ -1,3 +1,12 @@
<PAMDataset>
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS>
<PAMRasterBand band="1">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't remember if we want this or not, but perhaps it's harmless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it doesn't affect the tests. I got tired of reseting the file every time I ran tests.

Comment thread src/options.rs Outdated
Comment thread src/cpl.rs
}
}

impl Extend<CslStringListEntry> for CslStringList {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Too bad we can't use CSLMerge here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually started to implement it (and still can) but the C++ implementation scared me as I saw no evidence that it would extend the length of the original array. That said, my C++ is 20 years rusty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That function just appends one element at a time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Couldn't find a {re|m}alloc in there or in CSLSetNameValue either.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/cpl.rs
impl Extend<CslStringListEntry> for CslStringList {
fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T) {
for e in iter {
self.add_entry(&e).unwrap_or_default();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oof 😔.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lnicola Here's my rational as to why this might be OK.
Most of the time you're going to be extending one CslStringList with another. The only way that call can fail is if your insertion String has \r, \n, or most importantly \0. If iter comes from a CslStringList then that validation has already happened.

However, if iter comes from [CslStringListEntry], then you could presumably circumvent that check. I added this comment for that reason.

The obvious alternative means no Extend, and TryFroms to cover what is probably a rare edge case. On balance, I'd rather have Extend.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Exactly. OOM might be another case where it fails, but it's pretty unlikely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FWIW, Added additional documentation to CslStringListEntry::new_{pair|flag}.

Comment thread src/cpl.rs

@lnicola lnicola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error handling makes this a bit icky, but I don't have any good suggestions.

I think it's workable, if not ideal, let's see how jdroenner, feels about it.

@metasim

metasim commented Nov 1, 2023

Copy link
Copy Markdown
Contributor Author

@jdroenner r+?

Comment thread src/cpl.rs
///
/// An Entry is ether a single token (`Flag`), or a `name=value` assignment (`Pair`).
///
/// Note: When constructed directly, assumes string values do not contain newline characters nor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably spell out more clearly that those values will be ignored. And not just here, but also on CslStringList.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CslStringList actually propagates the error.

gdal/src/cpl.rs

Lines 116 to 117 in 16f2aef

Self::check_valid_name(name)?;
Self::check_valid_value(value)?;

@metasim
metasim force-pushed the feature/csl-extend branch from caa66a6 to ff6a0e3 Compare November 6, 2023 17:12
@metasim

metasim commented Nov 6, 2023

Copy link
Copy Markdown
Contributor Author

bors r=lnicola

@metasim

metasim commented Nov 6, 2023

Copy link
Copy Markdown
Contributor Author

bors try

@metasim
metasim merged commit a1aee76 into georust:master Nov 6, 2023
@metasim
metasim deleted the feature/csl-extend branch November 6, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants