[][src]Struct memsocket::MemorySocket

pub struct MemorySocket { /* fields omitted */ }

An in-memory stream between two local sockets.

A MemorySocket can either be created by connecting to an endpoint, via the connect method, or by accepting a connection from a listener. It can be read or written to using the AsyncRead, AsyncWrite, and related extension traits in futures::io.

Examples

use futures::prelude::*;
use memsocket::MemorySocket;

let (mut socket_a, mut socket_b) = MemorySocket::new_pair();

socket_a.write_all(b"stormlight").await?;
socket_a.flush().await?;

let mut buf = [0; 10];
socket_b.read_exact(&mut buf).await?;
assert_eq!(&buf, b"stormlight");

Implementations

impl MemorySocket[src]

pub fn new_pair() -> (Self, Self)[src]

Construct both sides of an in-memory socket.

Examples

use memsocket::MemorySocket;

let (socket_a, socket_b) = MemorySocket::new_pair();

pub fn connect(port: u16) -> Result<MemorySocket>[src]

Create a new in-memory Socket connected to the specified port.

This function will create a new MemorySocket socket and attempt to connect it to the port provided.

Examples

use memsocket::MemorySocket;

let socket = MemorySocket::connect(16)?;

Trait Implementations

impl AsyncRead for MemorySocket[src]

fn poll_read(
    self: Pin<&mut Self>,
    context: &mut Context<'_>,
    buf: &mut [u8]
) -> Poll<Result<usize>>
[src]

Attempt to read from the AsyncRead into buf.

impl AsyncWrite for MemorySocket[src]

fn poll_write(
    self: Pin<&mut Self>,
    context: &mut Context<'_>,
    buf: &[u8]
) -> Poll<Result<usize>>
[src]

Attempt to write bytes from buf into the outgoing channel.

fn poll_flush(
    self: Pin<&mut Self>,
    _context: &mut Context<'_>
) -> Poll<Result<()>>
[src]

Attempt to flush the channel. Cannot Fail.

fn poll_close(
    self: Pin<&mut Self>,
    _context: &mut Context<'_>
) -> Poll<Result<()>>
[src]

Attempt to close the channel. Cannot Fail.

impl Debug for MemorySocket[src]

Auto Trait Implementations

impl !RefUnwindSafe for MemorySocket

impl Send for MemorySocket

impl Sync for MemorySocket

impl Unpin for MemorySocket

impl !UnwindSafe for MemorySocket

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.