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

Support derive(Any) type protocols #583

Open
ModProg opened this issue Jul 19, 2023 · 1 comment · May be fixed by #587
Open

Support derive(Any) type protocols #583

ModProg opened this issue Jul 19, 2023 · 1 comment · May be fixed by #587
Labels
enhancement New feature or request

Comments

@ModProg
Copy link
Contributor

ModProg commented Jul 19, 2023

What I want is some way to use e.g. derived functions or trait implementations in general with derive(Any).

#[derive(Any, Debug, Display)]
#[display(fmt = "name = {value}")]
// STRING_DISPLAY uses the `Display` trait implementation
#[rune(item = ::std::env, protocols(STRING_DISPLAY, DEBUG = Self::debug)]
struct Var {
    name: String,
}

impl Var {
    // This would map debug to display instead of using the rust debug.
    fn debug(&self, buf: &mut String) -> fmt::Result {
        write!(buf, "{self}");
    }
}

I have put together something here: bbb3897 though I think it could have a nicer interface:

#[derive(Any, Clone, Display)]
#[rune(item = ::std::env, protocols = [STRING_DISPLAY])]
#[display(fmt = "{}", "value.as_deref().unwrap_or_default()")]
struct Var {
    name: String,
    value: Option<String>,
}
@ModProg
Copy link
Contributor Author

ModProg commented Jul 19, 2023

I would be willing to implement this.

ModProg added a commit to ModProg/rune that referenced this issue Jul 25, 2023
@ModProg ModProg linked a pull request Jul 25, 2023 that will close this issue
ModProg added a commit to ModProg/rune that referenced this issue Jul 25, 2023
@udoprog udoprog added the enhancement New feature or request label Aug 2, 2023
ModProg added a commit to ModProg/rune that referenced this issue Aug 3, 2023
@udoprog udoprog changed the title derive(Any) type protocols Support derive(Any) type protocols Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants