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

Use `T: AsRef<str>, &[T]` instead of `&[&str]` in various APIs

Open sdroege opened this issue 4 years ago • 5 comments

Much nicer to use if your strings are actual String.

Same thing applies for other &[&T] we might have in API somewhere as with AsRef both &[T] and &[&T] would be possible to pass in (and other AsRef impls of course).

sdroege avatar Feb 11 '21 17:02 sdroege

@pbor btw, this is why I mentioned that yesterday

sdroege avatar Apr 07 '21 13:04 sdroege

Does this issue also refers to all APIs that accept &str as argument as well? I see that those would also benefit from similar change.

rafaelcaricio avatar May 21 '21 20:05 rafaelcaricio

Do you have an example usage for that where it makes things better? For &str it's not really much of a problem as you can simply .as_str() / .as_ref() in your function call. For slices it's more difficult because that would require re-allocating the whole slice into a temporary Vec or so.

sdroege avatar May 22 '21 07:05 sdroege

@sdroege I think you're right, the &str argument is pretty straight forward to use with String. Maybe not worth the change after all.

rafaelcaricio avatar May 22 '21 09:05 rafaelcaricio

Yeah, I had troubles trying to use gio::Settings, set_strv while trying to push a single value into the setting.

A6GibKm avatar Aug 10 '21 08:08 A6GibKm

At this point this should probably rather make use of impl IntoStrV

sdroege avatar Jan 10 '23 07:01 sdroege

This would be covered by https://github.com/gtk-rs/gtk-rs-core/issues/884 now.

sdroege avatar Jan 21 '23 09:01 sdroege