Skip to content

Create custom derive macro for Arbitrary type. #726

@celinval

Description

@celinval

Requested feature: Create a proc_macro that allows users to annotate their structs and enums with #[derive(Invariant)]
Use case: Allow users to easily generate implementation of the Invariant types for their custom structs and enums whenever the invariant of their types is the combination of their field's invariant.
Link to relevant documentation (Rust reference, Nomicon, RFC):
Is this a breaking change? No

Test case:

#[derive(Invariant)]
enum Operation {
    Sum,
    Sub,
}

fn main() {
    let op : Operation = rmc::any();
    let v1 : i32 = rmc::any();
    let v2: i32 = rmc::any();
    calculate(v1, v2, op);
}

This should generate something like:

unsafe impl Invariant for Operation {
    fn is_valid(&self) -> bool {
        matches!(*self, Operation::Sum | Operation::Sub);
    }
}

Metadata

Metadata

Assignees

Labels

[C] Feature / EnhancementA new feature request or enhancement to an existing feature.[E] User ExperienceAn UX enhancement for an existing feature. Including deprecation of an existing one.

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions