-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature request: Ability to call functions on members, e.g. PathBuf::display() (was: How to display path members?) #11
Comments
There is no way to display anything other than the field. I hope to be able to implement |
Okay, thanks for the fast reply! Shall I close this, or leave it open as a feature request? |
I would like to close this issue after making it possible to use a method call, so please leave it open. |
I would like to use this feature for displaying members of
|
It might be nice to support a syntax for repetition, such as |
It occurs to me that having any way of doing this right now would also let us handle This seems like the escape hatch that can make it usable almost everywhere. And it would be nice to have a function specification support for from_str too. As far as syntax and readability goes, I don't think it's a problem, because if your expression is that complex, you should just make a function and call it instead. e.g. e.g. this helper I have in my personal std: pub struct FmtFn<F>(pub F)
where
F: Fn(&mut std::fmt::Formatter<'_>) -> std::fmt::Result;
impl<F> std::fmt::Display for FmtFn<F>
where
F: Fn(&mut std::fmt::Formatter<'_>) -> std::fmt::Result,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self.0)(f)
}
}
pub fn example(x: bool) -> impl std::fmt::Display {
FmtFn(move |fmt| write!(fmt, "Hi: {x:?}"))
} |
Consider:
How to derive
Display
for it? Is there some way to specify that the code needs to call.display()
on the member?The text was updated successfully, but these errors were encountered: