FromResponse

Trait FromResponse 

Source
pub trait FromResponse: Sized
where Self::Error: Display + Send,
{ type Error; // Required method fn from_response(msg: Response) -> Result<Self, Self::Error>; }
Expand description

Convert protocol buffer messages into domain-specific block types.

This trait is intended to simplify the deserialization and conversion process when streaming data from a Firehose gRPC service. Implementations of this trait provide a uniform way to transform a firehose_protos::Response message into a concrete type.

§Example

use firehose_client::FromResponse;
use firehose_protos::Response;

struct MyBlock;

impl FromResponse for MyBlock {
    fn from_response(msg: Response) -> Result<Self, ClientError> {
        // Perform conversion logic here.
        Ok(MyBlock)
    }
}

§Errors

Implementations should return a ProtosError if the conversion fails. This can occur due to invalid data, missing fields, or other deserialization issues.

§Usage

The FromResponse trait is typically used in conjunction with generic streaming methods, such as stream_blocks, allowing these methods to work with different block types by specifying the type parameter:

let stream = client
    .stream_blocks_generic::<FirehoseBeaconBlock>(start, total)
    .await?;

Required Associated Types§

Required Methods§

Source

fn from_response(msg: Response) -> Result<Self, Self::Error>

Convert a crate::Response into the implementing type.

§Parameters
  • msg: The Response message received from the Firehose stream.
§Returns

A Result containing the converted type on success, or a ClientError if the conversion fails.

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.

Implementors§