Skip to content

Commit ab99113

Browse files
authored
Merge pull request #72 from BGluth/latest_nightly_fix
Fixed compilation of latest nightly
2 parents 510e289 + 25830e5 commit ab99113

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(fn_traits, unboxed_closures)]
1+
#![feature(fn_traits, tuple_trait, unboxed_closures)]
22

33
//! Mocking framework for Rust (currently only nightly)
44
//!

src/mock_store.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::mocking::MockResult;
2-
use std::any::TypeId;
2+
use std::{any::TypeId, marker::Tuple};
33
use std::cell::RefCell;
44
use std::collections::HashMap;
55
use std::mem::transmute;
@@ -32,7 +32,7 @@ impl MockStore {
3232
self.layers.borrow_mut().pop();
3333
}
3434

35-
pub unsafe fn add_to_thread_layer<I, O>(
35+
pub unsafe fn add_to_thread_layer<I: Tuple, O>(
3636
&self,
3737
id: TypeId,
3838
mock: Box<dyn FnMut<I, Output = MockResult<I, O>> + 'static>,
@@ -44,7 +44,7 @@ impl MockStore {
4444
.add(id, mock);
4545
}
4646

47-
pub unsafe fn call<I, O>(&self, id: TypeId, mut input: I) -> MockResult<I, O> {
47+
pub unsafe fn call<I: Tuple, O>(&self, id: TypeId, mut input: I) -> MockResult<I, O> {
4848
// Do not hold RefCell borrow while calling mock, it can try to modify mocks
4949
let layer_count = self.layers.borrow().len();
5050
for layer_idx in (0..layer_count).rev() {
@@ -93,7 +93,7 @@ impl MockLayer {
9393
self.mocks.remove(&id);
9494
}
9595

96-
pub unsafe fn add<I, O>(
96+
pub unsafe fn add<I: Tuple, O>(
9797
&mut self,
9898
id: TypeId,
9999
mock: Box<dyn FnMut<I, Output = MockResult<I, O>> + 'static>,
@@ -118,19 +118,19 @@ struct ErasedStoredMock {
118118
}
119119

120120
impl ErasedStoredMock {
121-
unsafe fn call<I, O>(self, input: I) -> MockLayerResult<I, O> {
121+
unsafe fn call<I: Tuple, O>(self, input: I) -> MockLayerResult<I, O> {
122122
let unerased: StoredMock<I, O> = transmute(self.mock);
123123
unerased.call(input)
124124
}
125125
}
126126

127127
/// Guarantees that while mock is running it's not overwritten, destroyed, or called again
128128
#[derive(Clone)]
129-
struct StoredMock<I, O> {
129+
struct StoredMock<I: Tuple, O> {
130130
mock: Rc<RefCell<Box<dyn FnMut<I, Output = MockResult<I, O>>>>>,
131131
}
132132

133-
impl<I, O> StoredMock<I, O> {
133+
impl<I: Tuple, O> StoredMock<I, O> {
134134
fn new(mock: Box<dyn FnMut<I, Output = MockResult<I, O>> + 'static>) -> Self {
135135
StoredMock {
136136
mock: Rc::new(RefCell::new(mock)),

src/mocking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::mock_store::{MockLayer, MockStore};
2-
use std::any::{Any, TypeId};
2+
use std::{any::{Any, TypeId}, marker::Tuple};
33
use std::marker::PhantomData;
44
use std::mem::transmute;
55

@@ -8,7 +8,7 @@ use std::mem::transmute;
88
/// The trait is implemented for all functions, so its methods can be called on any function.
99
///
1010
/// Note: methods have any effect only if called on functions [annotated as mockable](https://docs.rs/mocktopus_macros).
11-
pub trait Mockable<T, O> {
11+
pub trait Mockable<T: Tuple, O> {
1212
/// Core function for setting up mocks
1313
///
1414
/// Always consider using [mock_safe](#tymethod.mock_safe) or [MockContext](struct.MockContext.html).
@@ -97,7 +97,7 @@ pub fn clear_mocks() {
9797
MOCK_STORE.with(|mock_store| mock_store.clear())
9898
}
9999

100-
impl<T, O, F: FnOnce<T, Output = O>> Mockable<T, O> for F {
100+
impl<T: Tuple, O, F: FnOnce<T, Output = O>> Mockable<T, O> for F {
101101
unsafe fn mock_raw<M: FnMut<T, Output = MockResult<T, O>>>(&self, mock: M) {
102102
let id = self.get_mock_id();
103103
let boxed = Box::new(mock) as Box<dyn FnMut<_, Output = _>>;
@@ -186,7 +186,7 @@ impl<'a> MockContext<'a> {
186186
///
187187
/// This function doesn't actually mock the function. It registers it as a
188188
/// function that will be mocked when [`run`](#method.run) is called.
189-
pub fn mock_safe<I, O, F, M>(self, mockable: F, mock: M) -> Self
189+
pub fn mock_safe<I: Tuple, O, F, M>(self, mockable: F, mock: M) -> Self
190190
where
191191
F: Mockable<I, O>,
192192
M: FnMut<I, Output = MockResult<I, O>> + 'a,
@@ -198,7 +198,7 @@ impl<'a> MockContext<'a> {
198198
///
199199
/// This is an unsafe version of [`mock_safe`](#method.mock_safe),
200200
/// without lifetime constraint on mock
201-
pub unsafe fn mock_raw<I, O, F, M>(mut self, mockable: F, mock: M) -> Self
201+
pub unsafe fn mock_raw<I: Tuple, O, F, M>(mut self, mockable: F, mock: M) -> Self
202202
where
203203
F: Mockable<I, O>,
204204
M: FnMut<I, Output = MockResult<I, O>>,

tests/injecting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(const_fn, proc_macro_hygiene)]
1+
#![feature(proc_macro_hygiene)]
22

33
// Test if injecting works even if mocktopus is aliased
44
extern crate mocktopus as mocktopus_aliased;

0 commit comments

Comments
 (0)