//! WebSocket receiver module.

use crate::{Message, Result, traits::WebSocketReceiverTrait};
use super::backend;

impl<Backend: WebSocketReceiverTrait> From<Backend> for WebSocketReceiver<Backend> {
    fn from(backend: Backend) -> Self {
        WebSocketReceiver { backend }
    }
}

/// Stream-based WebSocket receiver.
#[derive(Debug)]
pub struct WebSocketReceiver<Backend: WebSocketReceiverTrait = backend::WebSocketReceiver> {
    backend: Backend,
}

impl<Backend: WebSocketReceiverTrait> WebSocketReceiver<Backend> {
    /// Receives a message.
    pub async fn next(&mut self) -> Result<Option<Message>> {
        self.backend.next().await
    }
}
