Skip to content
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

Add an Option to use a Format String to Structs #94

Open
ModProg opened this issue Jun 27, 2021 · 0 comments
Open

Add an Option to use a Format String to Structs #94

ModProg opened this issue Jun 27, 2021 · 0 comments

Comments

@ModProg
Copy link

ModProg commented Jun 27, 2021

My Idea is to use something similar to thiserror where you specify a format string that get's filled with the fields:

#[derive(Error, Debug)]
pub enum DocumentError {
    #[error("Invalid {0}: `{1}`")]
    InvalidAttribute(String, String),
}

This could look like this for Debug of structs:

#[derive(Derivative)]
#[derivative(Debug(format="({x},{y}: {w})"))]
pub struct Point {
    pub x: f32,
    pub y: f32,
    pub w: f32,
}

I think most of the Time this is enough for formatting, and you don't actually need a function for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant