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.
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 Mockable for DapiClientError
impl Mockable for DapiClientError
Serialization of [DapiClientError].
We need to do manual serialization because of the generic type parameter which doesn’t support serde derive.
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<DapiClientError>
§impl Mockable for TransportError
impl Mockable for TransportError
Serialization of [TransportError].
We need to do manual serialization because of the generic type parameter which doesn’t support serde derive.
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<TransportError>
§impl<E> Mockable for ExecutionError<E>where
E: Mockable,
impl<E> Mockable for ExecutionError<E>where
E: Mockable,
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<ExecutionError<E>>
§impl<R> Mockable for ExecutionResponse<R>where
R: Mockable,
impl<R> Mockable for ExecutionResponse<R>where
R: Mockable,
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<ExecutionResponse<R>>
§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.