[][src]Attribute Macro faux::create

#[create]

Transforms the given struct into a mockable version of itself.

It creates an associated function for the tagged struct called faux and masks the original definition of the struct by changing its name.

Use cargo-expand to see what your struct expands to after the macro.

Requirements

This macro deliberately fails to compile if any of the struct's fields are not private. Otherwise, a user of the struct could try to access the field directly when it no longer exists in the transformed version.

The transformed struct is useless unless its methods are also mocked. See #[methods] for documentation on how to mock the methods of the struct. If #[methods] is not used for an impl block, methods inside the impl may not use any of its fields.

Known Limitations

#9: Mocked structs cannot have generic parameters

Usage

#[faux::create]
pub struct MyStruct {
    a: i32,
    b: Vec<u32>,
}

#[faux::methods]
impl MyStruct {
    /* methods go here */
}

// creates a mock out of MyStruct
let my_mock = MyStruct::faux();