use std::fmt::{self, Formatter};
use super::Mock;
pub struct Unchecked<'stub> {
unsafe_mock: Mock<'stub, (), ()>,
debug_repr: String,
}
impl<'stub> Unchecked<'stub> {
pub unsafe fn as_typed<I, O>(&self) -> &Mock<'stub, I, O> {
let mock = &self.unsafe_mock;
std::mem::transmute(mock)
}
pub unsafe fn as_typed_mut<I, O>(&mut self) -> &mut Mock<'stub, I, O> {
let mock = &mut self.unsafe_mock;
std::mem::transmute(mock)
}
}
impl fmt::Debug for Unchecked<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(&self.debug_repr)
}
}
impl<'stub, I, O> From<Mock<'stub, I, O>> for Unchecked<'stub> {
fn from(mock: Mock<I, O>) -> Self {
let debug_repr = format!("{:?}", mock);
unsafe {
let unsafe_mock: Mock<_, _> = std::mem::transmute(mock);
Self {
unsafe_mock,
debug_repr,
}
}
}
}