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§
Sourcefn 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.
Sourcefn 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", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Mockable for DapiClientError
Serialization of 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>
Source§impl Mockable for TransportError
Serialization of 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>
Source§impl Mockable for Box<TransportError>
Serialization of boxed TransportError.
impl Mockable for Box<TransportError>
Serialization of boxed TransportError.
fn mock_serialize(&self) -> Option<Vec<u8>>
fn mock_deserialize(data: &[u8]) -> Option<Box<TransportError>>
Source§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>>
Source§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 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.