Closed
Description
ToString
is specialized for string types to avoid using expensive formatting facility. This specialization can be missed by calling to_string
on redundantly-referenced strings like &&str
or &&String
which may easily occur when working with iterators, for example:
// Generic implementation for `T: Display` is used (slow)
["foo", "bar"].iter().map(|s| s.to_string());
// OK, the specialized impl is used
["foo", "bar"].iter().map(|&s| s.to_string());