app-dirs-rs icon indicating copy to clipboard operation
app-dirs-rs copied to clipboard

Owning strings

Open icefoxen opened this issue 8 years ago • 2 comments

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.

icefoxen avatar Apr 11 '17 18:04 icefoxen

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 avatar Feb 14 '18 05:02 daboross

@daboross That does actually look pretty cool, I didn't think of that.

icefoxen avatar Feb 20 '18 14:02 icefoxen