@calcopiritus @hatchet That way you can pass a reference or anything that can be turned into a reference as an argument. So the caller can supply a &T, Box, Rc, Arc, … (I dont’t know if there is a blanket impl so that even T itself will work.
internetionals
joined 2 years ago
@hatchet That is true and I mostly agree with you. AsRef makes function signatures more complex and you effectively change a simple function into a generic function.
That said, when using some crates that make heavy use of this construction (especially when working with owned values in call chains) is sometimes significantly more ergonomic.
So AsRef definitely had it’s uses, but I agree that it probably shouldn’t be the recommended “best practice” for all crates.