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

glib: Add get_transformed to Value #1250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZanderBrown
Copy link
Contributor

Like transform(), but actually gives you T instead of a new Value, which is probably what you wanted

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> {
Copy link
Member

Choose a reason for hiding this comment

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

to_transformed() maybe? It's a conversion, not a getter.

@pbor what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really more convenient than v.transform().get()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe if we want a shortcut we should implement TryInto ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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>

Copy link
Member

Choose a reason for hiding this comment

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

the other option is to rename this function to transform and rename the other transform function to transform_as_value or something like that

@bilelmoussaoui
Copy link
Member

Any update on this one?

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.

4 participants