-
-
Notifications
You must be signed in to change notification settings - Fork 133
Description
I noticed that gio::ApplicationCommandLine::environ returns a Vec<OsString> and that gio::SubprocessLauncher::set_environ only takes a &[&Path] as argument.
This seems rather unfortunate. My application should share a primary instance for multiple windows, but still needs to spawn processes with the environment that spawned a new window on the primary instance. This currently needs an intermediate collection to collect the Path references that can be passed to gio::SubprocessLauncher::set_environ.
let cmd: gio:ApplicationCommandLine; // from the parameter of the `gio::Application::command_line` signal
let launcher = gio::SubprocessLauncher::new();
launcher.set_environ(cmd.environ().iter().map(<OsString as AsRef<Path>>::as_ref).collect::<Vec<&Path>>().as_slice());This could be generic over all ToGlibContainerFromSlice types that coerce properly like &OsStr, &str, &Path and their owned variants OsString, String, PathBuf.
I think an intermediary trait for all kinds of OsStr-like values could help to make the gio::SubprocessLauncher::set_environ method more usable.
Maybe something like fn set_environ<'a>(&self, envs: &'a [impl AsOsStr<'a>])? Where AsOsStr<'a> is a subtrait of glib::translate::ToGlibContainerFromSlice<'a, *const *const i8> so the .to_glib_none() in the generated bindings still works?
trait AsOsStr<'a> : glib::translate::ToGlibContainerFromSlice<'a, *const *const i8> {}
impl<'a> AsOsStr<'a> for T where T: AsRef<OsStr> + glib::translate::ToGlibContainerFromSlice<'a, *const *const i8> {}On a side-note: Why doesn't CString and &CStr implement ToGlibContainerFromSlice?
It's just a minor inconvenience but I wanted to start some discussion on these OsStr-like slices in function arguments.