app-dirs-rs
app-dirs-rs copied to clipboard
Owning strings
PR to make AppInfo a trait and have different structures with different ownership semantics for it. Resolves issue #19
I still think there should be some way to use Cow to make this simpler, but it's less ergonomic. Oh well.
If ergonomics for Cow are a blocker, do you think it could be fixed with a new method like this?
pub fn new<U, A>(name: U, author: T)
where
U: Into<Cow<'static, str>>,
A: Into<Cow<'static, str>>,
{
AppInfo { name: name.into(), author: author.into() }
}
The pattern of accepting Into<Cow<str>> is one I've used a lot when I want to accept both String and &'static str in the same method. AppInfo::new("a", "b") and AppInfo::new("a".to_owned(), "b".to_owned()) should both work with this.
I realize this is an old PR which has been untouched; but if the trait design is why, it would be nice to fix it to have these improvements in the project.
@daboross That does actually look pretty cool, I didn't think of that.