scrap icon indicating copy to clipboard operation
scrap copied to clipboard

Display names.

Open quadrupleslap opened this issue 7 years ago • 3 comments
trafficstars

fn Display::name(&self) -> &str;

quadrupleslap avatar Apr 08 '18 11:04 quadrupleslap

Or maybe it should be:

fn Display::name(&self) -> Cow<str>;

quadrupleslap avatar Apr 11 '18 09:04 quadrupleslap

What is the benefit of Cow string?

I've come across this article which shows how it's good for an API where it takes a string from the user. Not sure how it's useful when it's the other way around though?

polarathene avatar Apr 11 '18 12:04 polarathene

It's useful because on macOS I'd need to allocate a string, but on Windows I wouldn't, and I think this is the best way to abstract over maybe allocating a string. I guess it could also be ... -> impl Into<String> + Borrow<str> or something like that, but that's more complicated.

Edit: Posted a question on the Rust user forums!

quadrupleslap avatar Apr 11 '18 12:04 quadrupleslap