-
Notifications
You must be signed in to change notification settings - Fork 94
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
Take the field index, not name, in the feature getters and setters #581
base: master
Are you sure you want to change the base?
Conversation
r? @metasim, @ChristianBeilschmidt, @jdroenner since this is a relatively big change Hopefully I'll be able to get rid of this thing soon: (it goes on and on) |
/// If the field is missing, returns [`GdalError::InvalidFieldName`]. | ||
/// | ||
pub fn field_index<S: AsRef<str>>(&self, field_name: S) -> Result<usize> { |
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.
To consider: Some of these retrieval functions return Result<Option<T>>
. Should that convention be used here? I'm on the fence. It arguably adds more friction but is more precise. At the other end of the spectrum is just Option<usize>
, which has nicer ergonomics, but basically swallows FFI-related errors.
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.
The Option
there is meant for null (or unset, but I'm not sure how well we support those) fields. For the getters, I think the "simple" ones are infallible and return some kind of 0 for invalid indexes, while the ones returning lists are fallible.
So Result<Option<T>>
sounds right for the getters and setters. field_index
could return Option<usize>
, but that's less nice to use (because it won't mix with Result
and ?
), and it does swallow the FFI errors.
I think this is nice, some questions... can we actually change the fields in any way that could broke the field id? From where is the image? I can see some transformations from |
You can delete fields from the
From Or we could go the other way around and introduce a |
CHANGES.md
if knowledge of this change could be valuable to users.Field access by name tends to be very slow (I've seen it take 30% of the time in some programs), but beginners are unlikely to realize that they're doing a number of expensive lookups per feature.
Summary of changes:
field_count
returnusize
for consistencyDefn::field_index
and makeFeature::field_index
publicLayerAccess::create_feature_fields
(it could be updated, but it's a bit weird)