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

[FEATURE REQUEST] Rename ToValue::value_type or ParamSpec::value_type #1228

Open
kawadakk opened this issue Nov 20, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@kawadakk
Copy link
Contributor

kawadakk commented Nov 20, 2023

ParamSpec implements ToValue, and both provide methods named value_type, which can lead to a surprising method resolution behavior when calling value_type with a method call syntax.

use glib::prelude::*;
glib::object::ObjectClass::from_type(gio::Application::static_type())
    .unwrap()
    .list_properties()
    .iter()
    .filter(|spec| spec.name() == "application-id")
    .inspect(|spec: &&ParamSpec| assert_eq!(spec.value_type(), glib::ParamSpec::static_type()))
    //                                          ^^^^^^^^^^^^^
    //                                          `<&ParamSpec as ToValue>::value_type`
    .for_each(|spec: &ParamSpec| assert_eq!(spec.value_type(), glib::Type::STRING));
    //                                          ^^^^^^^^^^^^^
    //                                          `ParamSpec::value_type`
@kawadakk kawadakk added the enhancement New feature or request label Nov 20, 2023
@sdroege
Copy link
Member

sdroege commented Nov 22, 2023

That makes sense. I think it should be ToValue::value_type() that should be renamed as that one is very unlikely to be called by user code.

Do you have any suggestions how to call it instead? @bilelmoussaoui @GuillaumeGomez @pbor you maybe?

@GuillaumeGomez
Copy link
Member

Not really... ^^'

@kawadakk
Copy link
Contributor Author

kawadakk commented Nov 22, 2023

How about ToValue::type_in_value()? ("Type of Self in the Value form")

This is based on the observation that a Rust value converted to glib::Value may take a different form (e.g., String and &str turn into G_TYPE_STRING that is a pointer to a null-terminated g_malloc-allocated string).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants