glib: Add get_transformed to Value#1250
Conversation
Like transform(), but actually gives you T instead of a new Value, which is probably what you wanted
| // rustdoc-stripper-ignore-next | ||
| /// Tries to transform the value into the target type | ||
| #[doc(alias = "g_value_transform")] | ||
| pub fn get_transformed<T: ValueType>(&self) -> Result<T, crate::BoolError> { |
There was a problem hiding this comment.
to_transformed() maybe? It's a conversion, not a getter.
@pbor what do you think?
There was a problem hiding this comment.
Is it really more convenient than v.transform().get()?
There was a problem hiding this comment.
Maybe if we want a shortcut we should implement TryInto ?
There was a problem hiding this comment.
to_transformed()maybe? It's a conversion, not a getter.
Yeah I was a bit stumped on naming, get_transformed as least made sense linguistically but I see your point. I guess the best name really would be transform …but we already have that.
Is it really more convenient than v.transform().get()?
Well, that doesn't compile, so …yes?
Maybe if we want a shortcut we should implement
TryInto?
I'd imagine that a TryInto would want to wrap get()? — Seems potentially footgun-y to have try_into() do coercion when get() doesn't, but idk maybe it would be fine.
There was a problem hiding this comment.
Another naming possibility is transform_to which has a precedent: https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib/struct.BindingGroupBuilder.html#method.transform_to though that actually returns Option<Value>
There was a problem hiding this comment.
the other option is to rename this function to transform and rename the other transform function to transform_as_value or something like that
|
Any update on this one? |
Like transform(), but actually gives you T instead of a new Value, which is probably what you wanted