diff --git a/src/lib.rs b/src/lib.rs index 8faf63e..15db78f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(fn_traits, unboxed_closures)] +#![feature(fn_traits, tuple_trait, unboxed_closures)] //! Mocking framework for Rust (currently only nightly) //! diff --git a/src/mock_store.rs b/src/mock_store.rs index 22df3f0..64f248c 100644 --- a/src/mock_store.rs +++ b/src/mock_store.rs @@ -1,5 +1,5 @@ use crate::mocking::MockResult; -use std::any::TypeId; +use std::{any::TypeId, marker::Tuple}; use std::cell::RefCell; use std::collections::HashMap; use std::mem::transmute; @@ -32,7 +32,7 @@ impl MockStore { self.layers.borrow_mut().pop(); } - pub unsafe fn add_to_thread_layer( + pub unsafe fn add_to_thread_layer( &self, id: TypeId, mock: Box> + 'static>, @@ -44,7 +44,7 @@ impl MockStore { .add(id, mock); } - pub unsafe fn call(&self, id: TypeId, mut input: I) -> MockResult { + pub unsafe fn call(&self, id: TypeId, mut input: I) -> MockResult { // Do not hold RefCell borrow while calling mock, it can try to modify mocks let layer_count = self.layers.borrow().len(); for layer_idx in (0..layer_count).rev() { @@ -93,7 +93,7 @@ impl MockLayer { self.mocks.remove(&id); } - pub unsafe fn add( + pub unsafe fn add( &mut self, id: TypeId, mock: Box> + 'static>, @@ -118,7 +118,7 @@ struct ErasedStoredMock { } impl ErasedStoredMock { - unsafe fn call(self, input: I) -> MockLayerResult { + unsafe fn call(self, input: I) -> MockLayerResult { let unerased: StoredMock = transmute(self.mock); unerased.call(input) } @@ -126,11 +126,11 @@ impl ErasedStoredMock { /// Guarantees that while mock is running it's not overwritten, destroyed, or called again #[derive(Clone)] -struct StoredMock { +struct StoredMock { mock: Rc>>>>, } -impl StoredMock { +impl StoredMock { fn new(mock: Box> + 'static>) -> Self { StoredMock { mock: Rc::new(RefCell::new(mock)), diff --git a/src/mocking.rs b/src/mocking.rs index f394a1e..9172e66 100644 --- a/src/mocking.rs +++ b/src/mocking.rs @@ -1,5 +1,5 @@ use crate::mock_store::{MockLayer, MockStore}; -use std::any::{Any, TypeId}; +use std::{any::{Any, TypeId}, marker::Tuple}; use std::marker::PhantomData; use std::mem::transmute; @@ -8,7 +8,7 @@ use std::mem::transmute; /// The trait is implemented for all functions, so its methods can be called on any function. /// /// Note: methods have any effect only if called on functions [annotated as mockable](https://docs.rs/mocktopus_macros). -pub trait Mockable { +pub trait Mockable { /// Core function for setting up mocks /// /// Always consider using [mock_safe](#tymethod.mock_safe) or [MockContext](struct.MockContext.html). @@ -97,7 +97,7 @@ pub fn clear_mocks() { MOCK_STORE.with(|mock_store| mock_store.clear()) } -impl> Mockable for F { +impl> Mockable for F { unsafe fn mock_raw>>(&self, mock: M) { let id = self.get_mock_id(); let boxed = Box::new(mock) as Box>; @@ -186,7 +186,7 @@ impl<'a> MockContext<'a> { /// /// This function doesn't actually mock the function. It registers it as a /// function that will be mocked when [`run`](#method.run) is called. - pub fn mock_safe(self, mockable: F, mock: M) -> Self + pub fn mock_safe(self, mockable: F, mock: M) -> Self where F: Mockable, M: FnMut> + 'a, @@ -198,7 +198,7 @@ impl<'a> MockContext<'a> { /// /// This is an unsafe version of [`mock_safe`](#method.mock_safe), /// without lifetime constraint on mock - pub unsafe fn mock_raw(mut self, mockable: F, mock: M) -> Self + pub unsafe fn mock_raw(mut self, mockable: F, mock: M) -> Self where F: Mockable, M: FnMut>, diff --git a/tests/injecting.rs b/tests/injecting.rs index 7767915..ba56594 100644 --- a/tests/injecting.rs +++ b/tests/injecting.rs @@ -1,4 +1,4 @@ -#![feature(const_fn, proc_macro_hygiene)] +#![feature(proc_macro_hygiene)] // Test if injecting works even if mocktopus is aliased extern crate mocktopus as mocktopus_aliased;