[−][src]Struct faux::WhenOnce
Similar to When but its methods will only make the mock active for a single call. This allows users to pass an FnOnce rather than an FnMut, thus allowing to move data into the closure through a move rather than only a borrow or mutable borrow.
Methods
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 can move data to the closure. The mocked method however can only be activated once unless its re-mocked.
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 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 can move data to the closure. The mocked method however can only be activated once unless its re-mocked.
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>,