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

Roll up type and value trait definitions into existing macro #23

Open
TheDan64 opened this issue Oct 26, 2017 · 0 comments
Open

Roll up type and value trait definitions into existing macro #23

TheDan64 opened this issue Oct 26, 2017 · 0 comments
Labels

Comments

@TheDan64
Copy link
Owner

As of #22, value and type trait definitions are no longer a part of the trait macro. It would be great to roll this all back up into the macro, but this would probably require procedural macros (at the very least for converting the associated enum type into a snake case method, if not more). Procedural macros only support derives right now IIRC and require a separate crate, both of which aren't ideal. Maybe we can hardcode the method name into the regular macro invocation to avoid the trouble...

I'm imagining something like:

trait_type_set! {
    /// Represents any LLVM type.
    AnyType requires AsTypeRef + Debug enumerated by AnyTypeEnum [
        BasicTypeEnum, IntType, FunctionType, FloatType, PointerType, StructType, ArrayType, VoidType, VectorType
    ]
}

Which would expand to:

/// Represents any LLVM type.
pub trait AnyType: AsTypeRef + Debug {
    /// Returns a `AnyTypeEnum` that represents the current type.
    fn as_any_type_enum(&self) -> AnyTypeEnum {
        AnyTypeEnum::new(self.as_type_ref())
    }
}

along with the trait impls for each provided type.

This isn't a big deal, but would make traits more DRY, so I'm leaving this as a wishlist item.

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

No branches or pull requests

1 participant