[][src]Trait in_stream::InStream

pub trait InStream<R: Sized + Debug + Send + Sync, W: Sized + Debug + Send + Sync>: Sized + Debug + Send + Sync {
    const URL_SCHEME: &'static str;

    fn raw_connect<C: InStreamConfig>(url: &Url2, config: C) -> Result<Self>;
fn remote_url(&self) -> Url2;
fn check_ready(&mut self) -> Result<bool>;
fn read(&mut self, data: R) -> Result<usize>;
fn write(&mut self, data: W) -> Result<usize>;
fn flush(&mut self) -> Result<()>; }

implement this trait to provide a stream endpoint / socket type connection works like combined std::io::{Read, Write}, but with generic types the underlying stream should be treated as non-blocking. For example, if this is a TLS stream, we may still need to complete a handshaking process before data can actually be written.

read will return WouldBlock if there is no pending data to be read write will buffer any data if the stream is not ready to write flush will block until pending data has been written

Associated Constants

const URL_SCHEME: &'static str

your implementation should work with a single url scheme/protocol if you need to support multiple (i.e. ws:// vs wss://) consider using macros/code generation to DRY

Loading content...

Required methods

fn raw_connect<C: InStreamConfig>(url: &Url2, config: C) -> Result<Self>

create a new connection / stream of this type. this function does the actual work of connecting, but it is recommended your struct provide a wrapper with a concrete config type

fn remote_url(&self) -> Url2

access the remote url this connection represents

fn check_ready(&mut self) -> Result<bool>

process the stream to see if any remaining handshake items can be completed returns true if stream is set-up and ready to send/receive note that you can write before this function returns true but your messages may be buffered / sent later

fn read(&mut self, data: R) -> Result<usize>

non-blocking read. if R is an array-type, success result is number of elements read otherwise it is 1

fn write(&mut self, data: W) -> Result<usize>

buffered write. Implementors should buffer data on WouldBlock

fn flush(&mut self) -> Result<()>

blocking flush all pending buffered write data.

Loading content...

Implementors

impl<'_, '_> InStream<&'_ mut [u8], &'_ [u8]> for InStreamMem[src]

const URL_SCHEME: &'static str[src]

we want a url like mem://

impl<'_, '_> InStream<&'_ mut [u8], &'_ [u8]> for InStreamTcp[src]

const URL_SCHEME: &'static str[src]

tcp streams should use urls like tcp://

impl<Sub: InStreamStd, '_> InStream<&'_ mut WsFrame, WsFrame> for InStreamWss<Sub>[src]

impl<Sub: InStreamStd, '_, '_> InStream<&'_ mut [u8], &'_ [u8]> for InStreamTls<Sub>[src]

Loading content...