galvanic-mock
galvanic-mock copied to clipboard
Can't mock a Send trait
Galvanic Mock cannot be used to mock a trait object that must be Send. Example:
fn send() {
let mock = new_mock!(SendTrait);
given! {
<mock as SendTrait>::foo() then_return () always;
}
mock.foo(0);
let _ = Box::new(mock) as Box<SendTrait + Send>;
}
gives the following error:
error[E0277]: `std::rc::Rc<(dyn std::any::Any + 'static)>` cannot be sent between threads safely
--> src/t_galvanic_mock.rs:99:1
|
99 | #[use_mocks]
| ^^^^^^^^^^^^ `std::rc::Rc<(dyn std::any::Any + 'static)>` cannot be sent between threads safely
|
= help: within `t_galvanic_mock::mod_t::mock::GivenBehaviour`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<(dyn std::any::Any + 'static)>`
= note: required because it appears within the type `t_galvanic_mock::mod_t::mock::GivenBehaviour`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<t_galvanic_mock::mod_t::mock::GivenBehaviour>`
= note: required because it appears within the type `alloc::raw_vec::RawVec<t_galvanic_mock::mod_t::mock::GivenBehaviour>`
= note: required because it appears within the type `std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>`
= note: required because it appears within the type `((&'static str, &'static str), std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>)`
= note: required because it appears within the type `std::marker::PhantomData<((&'static str, &'static str), std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>)>`
= note: required because it appears within the type `std::collections::hash::table::RawTable<(&'static str, &'static str), std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>>`
= note: required because it appears within the type `std::collections::HashMap<(&'static str, &'static str), std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>>`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::cell::RefCell<std::collections::HashMap<(&'static str, &'static str), std::vec::Vec<t_galvanic_mock::mod_t::mock::GivenBehaviour>>>`
= note: required because it appears within the type `t_galvanic_mock::mod_t::mock::Mock7638`
= note: required for the cast to the object type `dyn t_galvanic_mock::SendTrait + std::marker::Send`
Thanks, I haven't given much thought on Send at all when developing the crate. As mentioned in #5 I'm working on a rewrite, though I have no ETA yet. I'll make sure to consider "sendability" in the rewrite.