cover photo by Pixabay
Here is a bit of background on me
according to my company's org chart on Workday, my current title is "Senior Consul...
For further actions, you may consider blocking this person and/or reporting abuse
You can also use
S: AsRef<str>(ors: impl AsRef<str>) if you don’t need theStringownership within the function code. It’s just as common and ergonomic, and it saves on performance too. The only downside is that it doesn’t supportDisplay/ToStringtypes which don’t contain immediate string data.Ideally, it should’ve been possible to define a custom trait with a function which returns a
Cow<'a, str>, and provide blanket implementations for all types that a) implementAsRef<str>(returningCow::Borrowed(str)), and b) implementInto<String>but do not implementAsRef<str>(returningCow::Owned(String)). Alas, Rust currently doesn’t support custom generic specializations or non-union trait/type guard operators, since it’s a huge headache to do such features in a sound way, so that they cannot break SemVer guarantees after landing.What's the benefit to using
s: impl AsRef<str>overs: &str?I asked myself the above and then found this message board thread from 2016: users.rust-lang.org/t/idiomatic-st...
...seems this is not a new discussion we're having.