Closed sffc closed 3 weeks ago
The trait should only have things that can actually be specialized. Defaulted trait functions create maintenance burden and code bloat. I want to move more toward free utility functions (#5738).
I agree on avoiding exposing functions like this for overriding
Note that the assert_writeable_eq
impl gets a fair bit shorter with this change, because we reduced the surface of trait impl that we need to test.
I think a free function is good, but if you don't like the ergonomics, it could be added by trait injection
pub trait WriteableCmpBytes {
pub fn writeable_cmp_bytes(...)
}
impl<T: Writeable + ?Sized> WriteableCmpBytes for T { ... }
But I prefer free functions.
Additional context: I had originally made this a function on the trait because I had thought that it could be specialized for certain types. However, a year in, we haven't found cases where a concrete type can offer a more efficient implementation of this function than the default, according to the benchmarks in this PR. So, there is no longer a technical reason why it needs to be a trait function.
It simplifies writeable impls. There is no impact on benchmarks, either the new microbenchmark I added or the higher-level
strict_cmp
benchmark in the icu_locale_core crate: