[−][src]Struct faux::WhenOnce
Similar to When but only mocks once.
Mock closures may consume captured variables as the mock will not be called more than once.
Implementations
impl<'q, I, O> WhenOnce<'q, I, O>
[src]
pub unsafe fn then(self, mock: impl FnOnce(I) -> O + Send)
[src]
A mirror of When.then but the mock may consume captured variables.
Safety
Usage
#[faux::create] pub struct Foo {} #[faux::methods] impl Foo { pub fn single_arg(&self, a: &u8) -> Vec<i8> { /* implementation code */ } } fn main() { let mut mock = Foo::faux(); let vec = vec![25]; //moves vec to the closure unsafe { faux::when!(mock.single_arg).once().then(|_| vec); } assert_eq!(mock.single_arg(&8), vec![25]); }
pub fn then_do(self, mock: impl FnOnce() -> O + 'static + Send) where
O: 'static,
[src]
O: 'static,
A mirror of When.then_do but the mock may consume captured variables.
Usage
#[faux::create] pub struct Foo {} #[faux::methods] impl Foo { pub fn single_arg(&self, a: &u8) -> Vec<i8> { /* implementation code */ } } fn main() { let mut mock = Foo::faux(); let vec = vec![25]; //moves vec to the closure faux::when!(mock.single_arg).once().then_do(|| vec); assert_eq!(mock.single_arg(&8), vec![25]); }
pub fn then_return(self, mock: O) where
O: 'static + Send,
[src]
O: 'static + Send,
A mirror of When.then_return but the object does not need to be cloneable.
Usage
// this does not implement Clone #[derive(PartialEq, Eq, Debug)] pub struct NonCloneableData(i32); #[faux::create] pub struct Foo {} #[faux::methods] impl Foo { pub fn single_arg(&self, a: &u8) -> NonCloneableData { /* implementation code */ } } fn main() { let mut mock = Foo::faux(); faux::when!(mock.single_arg).once().then_return(NonCloneableData(2)); assert_eq!(mock.single_arg(&8), NonCloneableData(2)); }
pub fn safe_then(self, mock: impl FnOnce(I) -> O + 'static + Send) where
I: 'static,
O: 'static,
[src]
I: 'static,
O: 'static,
A mirror of When.safe_then but the mock may consume captured variables.
Usage
#[faux::create] pub struct Foo {} #[faux::methods] impl Foo { pub fn single_arg(&self, a: u8) -> Vec<i8> { /* implementation code */ } } fn main() { let mut mock = Foo::faux(); let vec = vec![25]; //moves vec to the closure faux::when!(mock.single_arg).once().safe_then(|_| vec); assert_eq!(mock.single_arg(8), vec![25]); }
Auto Trait Implementations
impl<'q, I, O> !RefUnwindSafe for WhenOnce<'q, I, O>
impl<'q, I, O> !Send for WhenOnce<'q, I, O>
impl<'q, I, O> !Sync for WhenOnce<'q, I, O>
impl<'q, I, O> Unpin for WhenOnce<'q, I, O>
impl<'q, I, O> !UnwindSafe for WhenOnce<'q, I, O>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,