[−][src]Derive Macro lain::Mutatable
#[derive(Mutatable)] { // Attributes available to this derive: #[lain] }
Automatically implements trait@lain::traits::Mutatable with basic randomization
Notes
- Any bitfields will automatically be set within the appropriate ranges.
- Min/max values for primitives can be specified using
#[lain(min = 10, max = 20)]
. - Fields can be ignored using #[lain(ignore)].
- Custom initializers can be specified using #[lain(initializer = "my_initializer_func()")]
Example
ⓘThis example deliberately fails to compile
extern crate lain; use lain::prelude::*; use lain::rand; #[derive(RandomChoice)] enum ChoiceValue { FirstChoice = 1, SecondChoice = 2, } #[derive(Default, Mutatable)] struct Foo { field1: u8, #[lain(bits = 7)] field2: u8, #[lain(bits = 1)] field3: u8, #[lain(max = 300)] field4: u32, choice_field: ChoiceValue, } let mutator = Mutator::new(rand::thread_rng()); let my_struct: Foo = Default::default(); my_struct.mutate()