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.
Object Safety§
This trait is not object safe.
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> 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.
§impl<T> Mockable for DumpData<T>
impl<T> Mockable for DumpData<T>
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(buf: &[u8]) -> Option<DumpData<T>>
§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<TE> Mockable for DapiClientError<TE>where
TE: Mockable,
impl<TE> Mockable for DapiClientError<TE>where
TE: Mockable,
Serialization of [DapiClientError].
We need to do manual serialization because of the generic type parameter which doesn’t support serde derive.