by yeslibertarian · 7y ago · 0 comments
Regardless, I want a library author to help me fall into the pit of performance success, not expect me to do it all for myself.
fn foo<T>(frob: T) where T: Borrow<Frob> {
// Do something with frob.borrow()
}
Due to monomorpization, foo is specialized for moves/clones when called as foo(frob) where frob is a value type or for borrows when called as foo(&frob). Similarly, you can use Clone, ToOwned or even Into for going in the opposite direction.Whether such functions are good taste in general is debatable ;).