intrepid-core 0.1.2

Manage complex async business logic with ease
Documentation
use crate::{Frame, MessageFrame};

use super::{
    extractor_error::{MessageFrameError, WrongFrameError},
    ExtractContext, Extractor,
};

#[derive(Clone, Debug)]
/// Retrieve a [`MessageFrame`] from a [`Frame`], but only if the frame is a message.
pub struct Message(pub MessageFrame);

impl<State> Extractor<State> for Message {
    type Error = MessageFrameError;

    fn extract(frame: Frame, _: &ExtractContext<State>) -> Result<Self, Self::Error> {
        match frame {
            Frame::Message(message) => Ok(Self(message)),
            _ => Err(WrongFrameError.into()),
        }
    }
}