gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

glib: Implement `IntoOptionalGStr` for plain string types

Open sdroege opened this issue 2 years ago • 4 comments

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

sdroege avatar Jan 13 '23 08:01 sdroege

TBH not a fan of this. I think Into<Option<String>> is getting too far away from idiomatic Rust

jf2048 avatar Jan 18 '23 05:01 jf2048

@jf2048 You probably want to comment in #805 then. This PR comes from the discussions there :)

sdroege avatar Jan 18 '23 08:01 sdroege

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 the sys 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 the sys crate should accept a non-Option argument to pass the value. Another function with an explicit name could allow selecting the None case.
  • In both cases, another function such as unset_*, discard_* or reset_* would allow switching from Some value to None when necessary.

fengalin avatar Jan 19 '23 15:01 fengalin

Thanks for the clarification! More functions but less arguments. I like this approach a lot.

GuillaumeGomez avatar Jan 19 '23 16:01 GuillaumeGomez