gtk-rs-core
gtk-rs-core copied to clipboard
glib: Implement `IntoOptionalGStr` for plain string types
This way strings can be passed to such functions without explicit Option
wrapping, see https://github.com/gtk-rs/gtk-rs-core/issues/805.
CC @jf2048 @fengalin
Not sure if we want this change already for this release
TBH not a fan of this. I think Into<Option<String>>
is getting too far away from idiomatic Rust
@jf2048 You probably want to comment in #805 then. This PR comes from the discussions there :)
My position has shifted two days after my initial try on #805. See this comment. Sorry if that lead to confusions, I made it clear in the initial comment now.
The short version of my most recent position is:
- If the
None
case is the default, then the function with the same name as in thesys
crate should NOT use any argument for the optional value. Another function with an explicit name would accept a non-Option
argument to pass the value when needed. - If the
Some
case is the default, then the function with the same name as in thesys
crate should accept a non-Option
argument to pass the value. Another function with an explicit name could allow selecting theNone
case. - In both cases, another function such as
unset_*
,discard_*
orreset_*
would allow switching fromSome
value toNone
when necessary.
Thanks for the clarification! More functions but less arguments. I like this approach a lot.