Theoretically, we can support this with the current syntax, because we can detect so-called trivial cases and transform them into delegation (we do parse formatting string literal anyway).
#[derive(derive_more::Display)]
#[display("{_0:?}")] // <--- it's clear to be a trivial delegation case
struct Num(usize);
would expand to
impl std::fmt::Display for Num {
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
let _0 = &self.0;
std::fmt::Debug::fmt(_0, fmtr)
}
}
rather than
impl std::fmt::Display for Num {
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
let _0 = &self.0;
write!(fmtr, "{_0:?}")
}
}
Resolves #321
Synopsis
See https://github.com/JelteF/derive_more/issues/321#issuecomment-1854069597:
Solution
See https://github.com/JelteF/derive_more/issues/321#issuecomment-1854382465:
Checklist