I want to write a universal function that takes any string ( &str / String ) for the convenience of the caller.
The internal function requires String , so I would also like to avoid unnecessary redistribution if the caller calls the function using String .
foo("borrowed"); foo(format!("owned"));
For accepting links, I know that I can use foo<S: AsRef<str>>(s: S) , but what about a different path?
I think a general argument based on ToOwned might work (works for &str , and I assume it is no-op on String ), but I cannot figure out the exact syntax.
generics ownership-semantics rust
Kornel
source share