-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong result using &[&dyn Formatter]
#458
Comments
@Dirbaio: Could you please specify what is wrong about the resulting logline? It seems legit to me 🤔 😄 |
It should be
but it's actually
|
I think the solution here is to only perform the optimization if the element type explicitly supports it (presumably via a default-implemented but hidden method of the |
Ah, but we'd also have to make sure we don't use that method through the trait object, I'm not sure if that's possible |
It seems like it could be made to work by replacing the impl<T> Format for &'_ T
where
T: Format,
{
fn format(&self, fmt: Formatter) {
T::format(self, fmt)
}
}
impl Format for &'_ str {
fn format(&self, fmt: Formatter) {
str::format(self, fmt)
}
}
impl<T> Format for &'_ [T]
where
T: Format,
{
fn format(&self, fmt: Formatter) {
<[T]>::format(self, fmt)
}
}
impl Format for &'_ dyn Format {
fn format(&self, fmt: Formatter) {
<dyn Format>::format(self, fmt)
}
} ...then all but the last impl could opt into "static tags" if |
I wonder if the needs_tag optimization is too complex? What if the Format trait were something like this:
Formats The impl for This is less efficient because it'll still repeat the inner tags, but I think printing slices of deep structs is less common. This maybe gives 80% of the wire-size savings with 20% of the complexity which might be a worthy tradeoff? More complexity means higher code size too... |
the new format trait (PR #508) is not object safe so trait objects are no longer supported. Closing this issue because it no longer applies. |
This is a trickier version of #455. The
needs_tag
optimization can be broken even without using manual Format impls.prints
The text was updated successfully, but these errors were encountered: