Trait Mockable
pub trait Mockable: Sized {
// Provided methods
fn mock_serialize(&self) -> Option<Vec<u8>> { ... }
fn mock_deserialize(_data: &[u8]) -> Option<Self> { ... }
}Expand description
Mocking support for messages.
This trait should be implemented by any object that can be used in the DAPI.
We use serde_json to serialize/deserialize messages.
Provided Methods§
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_serialize(&self) -> Option<Vec<u8>>
Serialize the message to bytes for mocking purposes.
Returns None if the message is not serializable or mocking is disabled.
§Panics
Panics on any error.
fn mock_deserialize(_data: &[u8]) -> Option<Self>
fn mock_deserialize(_data: &[u8]) -> Option<Self>
Deserialize the message serialized with [mock_serialize()].
Returns None if the message is not serializable or mocking is disabled.
§Panics
Panics on any error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
§impl Mockable for Status
impl Mockable for Status
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<Status>
§impl<T, E> Mockable for Result<T, E>
impl<T, E> Mockable for Result<T, E>
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<Result<T, E>>
§impl<T> Mockable for Option<T>where
T: Mockable,
impl<T> Mockable for Option<T>where
T: Mockable,
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<Option<T>>
impl<T> Mockable for Streaming<T>where
T: Mockable,
Mocking of gRPC streaming responses is not supported.
This will return None on serialization,
effectively disabling mocking of streaming responses.