Trait rocket::data::IoHandler

source ·
pub trait IoHandler: Send {
    // Required method
    fn io<'async_trait>(
        self: Box<Self>,
        io: IoStream
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

An upgraded connection I/O handler.

An I/O handler performs raw I/O via the passed in IoStream, which is AsyncRead, AsyncWrite, and Unpin.

§Example

The example below implements an EchoHandler that echos the raw bytes back to the client.

use std::pin::Pin;

use rocket::tokio::io;
use rocket::data::{IoHandler, IoStream};

struct EchoHandler;

#[rocket::async_trait]
impl IoHandler for EchoHandler {
    async fn io(self: Box<Self>, io: IoStream) -> io::Result<()> {
        let (mut reader, mut writer) = io::split(io);
        io::copy(&mut reader, &mut writer).await?;
        Ok(())
    }
}

Required Methods§

source

fn io<'async_trait>( self: Box<Self>, io: IoStream ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Performs the raw I/O.

Implementations on Foreign Types§

source§

impl IoHandler for ()

source§

fn io<'async_trait>( self: Box<Self>, __arg1: IoStream ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Implementors§