Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

glib: Add a Value::downcast_mut() function #205

Closed
wants to merge 1 commit into from

Conversation

ids1024
Copy link
Contributor

@ids1024 ids1024 commented Dec 9, 2020

Useful since TypedValue::set* take &mut self.

Useful since `TypedValue::set*` take `&mut self`.
@ids1024 ids1024 force-pushed the value-downcast_mut branch from ebd6a4f to c6087ae Compare December 9, 2020 03:50
@sdroege
Copy link
Member

sdroege commented Dec 9, 2020

Makes sense, but TypedValue was planned to get removed as part of #31 . Do you actually use this in a useful way? If so, how? In my experience keeping Rust values around in the code and calling to_value() where needed is more convenient.

@ids1024
Copy link
Contributor Author

ids1024 commented Dec 9, 2020

As far as I can tell, without downcasting to a mutable TypedValue, there isn't a way to safe way to set the value of an existing Value. (SetValue::set_value is an unsafe unchecked way to do this).

I am trying to add a binding for g_settings_bind_with_mapping, which requires a callback to set the Value passed as an argument. I assume there are other APIs requiring something similar.

@sdroege
Copy link
Member

sdroege commented Dec 9, 2020

You'd assign a new value, that's effectively the same.

@ids1024
Copy link
Contributor Author

ids1024 commented Dec 9, 2020

Ok, assigning like that seems to work.

I like the idea having typed versions of things like this, but I guess it's reasonable enough to remove it if no one can find cases where it's especially useful. It does complicate things.

@sdroege
Copy link
Member

sdroege commented Dec 9, 2020

Yeah I like it too in principle, but I never had use for it or where I could use it, not using it was actually simpler. It only seems to complicate things compared to just passing Values around where needed and elsewhere keeping everything in a proper Rust type.

@ids1024 ids1024 closed this Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants