Struct IoManagerBuilder

Source
pub struct IoManagerBuilder<SinkType, StreamType, BF = fn(<StreamType as Stream>::Item, &mut IoWriter<<SinkType as Sink>::SinkItem>) -> Option<<StreamType as Stream>::Item>, BEH = fn(<StreamType as Stream>::Error)>
where SinkType: Sink, StreamType: Stream, BF: FnMut(<StreamType as Stream>::Item, &mut IoWriter<<SinkType as Sink>::SinkItem>) -> Option<<StreamType as Stream>::Item> + Send + 'static, BEH: FnMut(<StreamType as Stream>::Error) + Send + 'static,
{ /* private fields */ }
Expand description

A builder for IoManager, and the only way to build one since the constructors have been deleted.

Implementations§

Source§

impl<SinkType, StreamType> IoManagerBuilder<SinkType, StreamType>
where SinkType: Sink + Send + 'static, StreamType: Stream + Send + 'static, <StreamType as Stream>::Item: Send + Clone + 'static, <StreamType as Stream>::Error: Send, <SinkType as Sink>::SinkItem: Send + 'static,

Source

pub fn new( sink: SinkType, stream: StreamType, ) -> IoManagerBuilder<SinkType, StreamType, fn(<StreamType as Stream>::Item, &mut IoWriter<<SinkType as Sink>::SinkItem>) -> Option<<StreamType as Stream>::Item>, fn(<StreamType as Stream>::Error)>

Creates a builder for IoManager.

Examples found in repository?
examples/tcp_server.rs (line 54)
51fn process_socket(socket: TcpStream) {
52    println!("New Client");
53    let (sink, stream) = LineCodec.framed(socket).split();
54    let trx = IoManagerBuilder::new(sink, stream)
55        .with_filter(|frame, writer| {
56            if frame.to_lowercase().contains("hello there") {
57                writer.write("General Kenobi!".to_string());
58                return None;
59            }
60            Some(frame)
61        })
62        .with_error_handler(move |error| {
63            println!("{}", error);
64        })
65        .build();
66    let mut writer = trx.get_writer();
67    trx.on_receive(move |frame| {
68        println!("Got frame: {}", frame);
69        writer.write("Hi there".to_string());
70        Ok(())
71    });
72}
Source§

impl<SinkType, StreamType, FilterType, ErrorHandlerType> IoManagerBuilder<SinkType, StreamType, FilterType, ErrorHandlerType>
where SinkType: Sink + Send + 'static, StreamType: Stream + Send + 'static, <StreamType as Stream>::Item: Send + Clone + 'static, <StreamType as Stream>::Error: Send, <SinkType as Sink>::SinkItem: Send + 'static, FilterType: Filter<<SinkType as Sink>::SinkItem, <StreamType as Stream>::Item>, ErrorHandlerType: ErrorHandler<<StreamType as Stream>::Error>,

Source

pub fn with_filter<NewFilterType>( self, filter: NewFilterType, ) -> IoManagerBuilder<SinkType, StreamType, NewFilterType, ErrorHandlerType>
where NewFilterType: Filter<<SinkType as Sink>::SinkItem, <StreamType as Stream>::Item>,

Adds a filter to the IoManager builder. Filters are static in this library. If you need to be able to change the filter without droping the sink and steram passed to this instance, you should probably use Box to encapsulate your filter, and then whatever you need to make it all thread safe for when you’ll need to modify it. Type inference should still work, which is nice.

Examples found in repository?
examples/tcp_server.rs (lines 55-61)
51fn process_socket(socket: TcpStream) {
52    println!("New Client");
53    let (sink, stream) = LineCodec.framed(socket).split();
54    let trx = IoManagerBuilder::new(sink, stream)
55        .with_filter(|frame, writer| {
56            if frame.to_lowercase().contains("hello there") {
57                writer.write("General Kenobi!".to_string());
58                return None;
59            }
60            Some(frame)
61        })
62        .with_error_handler(move |error| {
63            println!("{}", error);
64        })
65        .build();
66    let mut writer = trx.get_writer();
67    trx.on_receive(move |frame| {
68        println!("Got frame: {}", frame);
69        writer.write("Hi there".to_string());
70        Ok(())
71    });
72}
Source

pub fn with_error_handler<NewErrorHandlerType>( self, handler: NewErrorHandlerType, ) -> IoManagerBuilder<SinkType, StreamType, FilterType, NewErrorHandlerType>
where NewErrorHandlerType: ErrorHandler<<StreamType as Stream>::Error>,

Similar to with_filter, only for error handling. Tip: if you want to be able to catch end of streams with this API, you may want your Codec to implement decode_eof() and throw an error at the last moment, such as this:

fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
    let decode = self.decode(buf);
    match decode {
        Ok(None) => Err(std::io::Error::from(std::io::ErrorKind::ConnectionAborted)),
        _ => decode,
    }
}
Examples found in repository?
examples/tcp_server.rs (lines 62-64)
51fn process_socket(socket: TcpStream) {
52    println!("New Client");
53    let (sink, stream) = LineCodec.framed(socket).split();
54    let trx = IoManagerBuilder::new(sink, stream)
55        .with_filter(|frame, writer| {
56            if frame.to_lowercase().contains("hello there") {
57                writer.write("General Kenobi!".to_string());
58                return None;
59            }
60            Some(frame)
61        })
62        .with_error_handler(move |error| {
63            println!("{}", error);
64        })
65        .build();
66    let mut writer = trx.get_writer();
67    trx.on_receive(move |frame| {
68        println!("Got frame: {}", frame);
69        writer.write("Hi there".to_string());
70        Ok(())
71    });
72}
Source

pub fn build(self) -> IoManager<SinkType::SinkItem, StreamType::Item>

Examples found in repository?
examples/tcp_server.rs (line 65)
51fn process_socket(socket: TcpStream) {
52    println!("New Client");
53    let (sink, stream) = LineCodec.framed(socket).split();
54    let trx = IoManagerBuilder::new(sink, stream)
55        .with_filter(|frame, writer| {
56            if frame.to_lowercase().contains("hello there") {
57                writer.write("General Kenobi!".to_string());
58                return None;
59            }
60            Some(frame)
61        })
62        .with_error_handler(move |error| {
63            println!("{}", error);
64        })
65        .build();
66    let mut writer = trx.get_writer();
67    trx.on_receive(move |frame| {
68        println!("Got frame: {}", frame);
69        writer.write("Hi there".to_string());
70        Ok(())
71    });
72}

Auto Trait Implementations§

§

impl<SinkType, StreamType, BF, BEH> Freeze for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: Freeze, StreamType: Freeze, BF: Freeze, BEH: Freeze,

§

impl<SinkType, StreamType, BF, BEH> RefUnwindSafe for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: RefUnwindSafe, StreamType: RefUnwindSafe, BF: RefUnwindSafe, BEH: RefUnwindSafe,

§

impl<SinkType, StreamType, BF, BEH> Send for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: Send, StreamType: Send,

§

impl<SinkType, StreamType, BF, BEH> Sync for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: Sync, StreamType: Sync, BF: Sync, BEH: Sync,

§

impl<SinkType, StreamType, BF, BEH> Unpin for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: Unpin, StreamType: Unpin, BF: Unpin, BEH: Unpin,

§

impl<SinkType, StreamType, BF, BEH> UnwindSafe for IoManagerBuilder<SinkType, StreamType, BF, BEH>
where SinkType: UnwindSafe, StreamType: UnwindSafe, BF: UnwindSafe, BEH: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T