Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder<'id, Op: Operation, Frame = WireFrame> {
    type Event;

    // Required methods
    fn classify(&self, frame: Frame) -> WireEvent<Self::Event>;
    fn decode(
        &mut self,
        event: Self::Event,
        out: Out<'id, Op>,
    ) -> Result<Flow, ProviderError>;

    // Provided method
    fn eof(&mut self, out: Out<'id, Op>) -> Result<Flow, ProviderError> { ... }
}
Expand description

Synchronous state machine for one reply. It classifies frames and decodes known events into the reply’s writer, without transport access and without being told how the reply arrives. HTTP wires read WireFrames; other transports name their own frame type.

Required Associated Types§

Source

type Event

The wire’s typed event, produced by this decoder’s classifier.

Required Methods§

Source

fn classify(&self, frame: Frame) -> WireEvent<Self::Event>

Decode and classify one frame. A JSON wire MUST delegate to a classifier in crate::providers::internal::wire, so the decode-then-validate policy is not re-derived per provider.

Source

fn decode( &mut self, event: Self::Event, out: Out<'id, Op>, ) -> Result<Flow, ProviderError>

Write one Known event into the reply. An error ends the reply with it.

Provided Methods§

Source

fn eof(&mut self, out: Out<'id, Op>) -> Result<Flow, ProviderError>

The frames ran out without an end. A decoder that already saw the provider’s end, in a form the provider sends before its last frame, ends the reply here; otherwise the reply is truncated.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'id, Op> Decoder<'id, Op> for Json
where Op: Operation<Emit = Free>, Op::End: DeserializeOwned,

Source§

type Event = (<Op as Operation>::End, Value)

Source§

impl<'id> Decoder<'id, AudioGeneration> for SpeechDecoder

Available on crate feature audio only.
Source§

impl<'id> Decoder<'id, Completion, MockFrame> for MockDecoder<'id>

Available on crate feature test-utils only.
Source§

impl<'id> Decoder<'id, Completion> for rig_core::providers::cohere::streaming::ChatDecoder

Source§

impl<'id> Decoder<'id, Completion> for rig_core::providers::ollama::streaming::ChatDecoder

Source§

impl<'id> Decoder<'id, Completion> for CohereDecoder

Source§

impl<'id> Decoder<'id, Completion> for GenerateContentDecoder

Source§

impl<'id> Decoder<'id, Completion> for InteractionsDecoder

EOF without interaction.completed is truncation, not successful completion, so the decoder has nothing to add at the end of the reply.

Source§

impl<'id> Decoder<'id, Completion> for MessagesDecoder

Source§

impl<'id> Decoder<'id, Completion> for OpenAiDecoder

Source§

impl<'id> Decoder<'id, Completion> for ResponsesDecoder

Source§

impl<'id> Decoder<'id, ContextCache> for CachedContentsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for rig_core::providers::cohere::embeddings::EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for rig_core::providers::gemini::embedding::EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for rig_core::providers::ollama::embedding::EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for rig_core::providers::openai::wire::EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for rig_core::providers::voyageai::wire::EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, ImageEmbedding> for ImageEmbeddingsDecoder

Source§

impl<'id> Decoder<'id, ImageGeneration> for rig_core::providers::gemini::image_generation::ImagesDecoder

Available on crate feature image only.
Source§

impl<'id> Decoder<'id, ImageGeneration> for rig_core::providers::openai::wire::ImagesDecoder

Available on crate feature image only.
Source§

impl<'id> Decoder<'id, ModelListing> for rig_core::providers::anthropic::modality::ModelsDecoder

Source§

type Event = ModelsPage

Source§

impl<'id> Decoder<'id, ModelListing> for rig_core::providers::copilot::model_listing::ModelsDecoder

Source§

impl<'id> Decoder<'id, ModelListing> for rig_core::providers::gemini::model_listing::ModelsDecoder

Source§

impl<'id> Decoder<'id, ModelListing> for rig_core::providers::ollama::model_listing::ModelsDecoder

Source§

impl<'id> Decoder<'id, ModelListing> for rig_core::providers::openai::wire::ModelsDecoder

Source§

impl<'id> Decoder<'id, Rerank> for rig_core::providers::openai::wire::RerankDecoder

Source§

impl<'id> Decoder<'id, Rerank> for rig_core::providers::voyageai::wire::RerankDecoder

Source§

impl<'id> Decoder<'id, Transcription> for rig_core::providers::gemini::transcription::TranscriptionsDecoder

Source§

impl<'id> Decoder<'id, Transcription> for rig_core::providers::openai::wire::TranscriptionsDecoder

Source§

impl<'id> Decoder<'id, Verify> for VerifyDecoder

Source§

impl<'id> Decoder<'id, Verify> for VerifyKeyDecoder