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

odra::interface #87

Closed
zie1ony opened this issue Mar 1, 2023 · 0 comments
Closed

odra::interface #87

zie1ony opened this issue Mar 1, 2023 · 0 comments
Labels
feature Full feature description not ready Design still need to more work

Comments

@zie1ony
Copy link
Contributor

zie1ony commented Mar 1, 2023

Consider allowing multiple trait implementations on a module.

trait ContractDef {
    fn def() -> Vec<String>;
}

// #[odra::interface]
trait ERC20Interface {
    fn transfer(&mut self);
    fn balance_of(&self);
}

// #[autogenerated]
impl ContractDef for dyn ERC20Interface {
    fn def() -> Vec<String> {
        vec![
            String::from("transfer"),
            String::from("balance_of")
        ]
    }
}

// #[odra::interface]
trait ERC20MetadataInterface {
    fn name(&self);
}

// #[autogenerated]
impl ContractDef for dyn ERC20MetadataInterface {
    fn def() -> Vec<String> {
        vec![
            String::from("name"),
        ]
    }
}

// #[odra::module]
struct Token;

impl ERC20Interface for Token {
    fn transfer(&mut self) {}
    fn balance_of(&self) {}
}

impl ERC20MetadataInterface for Token {
    fn name(&self) {}
}

// #[autogenerated]
impl ContractDef for Token {
    fn def() -> Vec<String> {
        let mut def = Vec::new();
        def.extend_from_slice(&<dyn ERC20Interface as ContractDef>::def());
        def.extend_from_slice(&<dyn ERC20MetadataInterface as ContractDef>::def());
        def
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        assert_eq!(Token::def(), vec![
            String::from("transfer"),
            String::from("balance_of"),
            String::from("name"),
        ]);
    }
}
@zie1ony zie1ony added this to the Future milestone Jun 22, 2023
@zie1ony zie1ony added feature Full feature description not ready Design still need to more work labels Jun 22, 2023
@zie1ony zie1ony removed this from the Future milestone Nov 28, 2023
@zie1ony zie1ony closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Full feature description not ready Design still need to more work
Projects
Status: ✅ Done
Development

No branches or pull requests

1 participant