pub struct Clause(_);
Expand description

A clause from which unimock instances are created.

There can be more than one clause for each MockFn instance, these will be combined together at construction time.

Clause is non-generic and uses dynamic dispatch internally. It also implements From<I> where I: IntoIterator<Item = Clause>, so one clause can contain several other clauses in a hierarchical manner. This means that clauses can be returned from helper functions and reused several times:

use unimock::*;
#[unimock]
trait Foo {
    fn foo(&self, i: i32) -> i32;
}

#[unimock]
trait Bar {
    fn bar(&self, i: i32) -> i32;
}

#[unimock]
trait Baz {
    fn baz(&self, i: i32) -> i32;
}

// reusable function
fn foo_bar_setup_clause() -> Clause {
    [
        Foo__foo.each_call(matching!(_)).returns(1).in_any_order(),
        Bar__bar.each_call(matching!(_)).returns(2).in_any_order(),
    ]
    .into()
}

let unimock = mock([
    foo_bar_setup_clause(),
    Baz__baz.each_call(matching!(_)).returns(3).in_any_order()
]);
assert_eq!(6, unimock.foo(0) + unimock.bar(0) + unimock.baz(0));

Trait Implementations

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.