intrepid_core/extract/
message.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{Context, Frame, MessageFrame};

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

#[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, _: &Context<State>) -> Result<Self, Self::Error> {
        match frame {
            Frame::Message(message) => Ok(Self(message)),
            _ => Err(WrongFrameError.into()),
        }
    }
}