Struct trillium_http::transport::BoxedTransport[][src]

pub struct BoxedTransport(_);
Expand description

A type for dyn Transport trait objects

BoxedTransport represents a Box<dyn Transport> that supports downcasting to the original Transport. This is used in trillium to erase the generic on Conn, in order to avoid writing Conn<TcpStream> throughout an application.

Stability Note: This may go away at some point and be replaced by a type alias exported from a trillium_server_common::Server crate.

Implementations

Create a new BoxedTransport from some Transport.

use trillium_http::transport::BoxedTransport;
use trillium_testing::TestTransport;
// this examples uses trillium_testing::TestTransport as an
// easily-constructed AsyncRead+AsyncWrite.
let (test_transport, _) = TestTransport::new();

let boxed = BoxedTransport::new(test_transport);

let downcast: Option<Box<TestTransport>> = boxed.downcast();
assert!(downcast.is_some());

let boxed_again = BoxedTransport::new(*downcast.unwrap());
assert!(boxed_again.downcast::<async_net::TcpStream>().is_none());

Attempt to convert the trait object into a specific transport T. This will only succeed if T is the type that was originally passed to BoxedTransport::new, and will return None otherwise

see BoxedTransport::new for example usage

Methods from Deref<Target = Box<dyn Transport + Send + Sync + 'static>>

Trait Implementations

Attempt to read from the AsyncRead into buf. Read more

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more

Attempt to write bytes from buf into the object. Read more

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more

Attempt to close the object. Read more

Attempt to write bytes from bufs into the object using vectored IO operations. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Reads some bytes from the byte stream. Read more

Like read(), except it reads into a slice of buffers. Read more

Reads the entire contents and appends them to a Vec. Read more

Reads the entire contents and appends them to a String. Read more

Reads the exact number of bytes required to fill buf. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Converts this [AsyncRead] into a [Stream] of bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more

Writes some bytes into the byte stream. Read more

Like write(), except that it writes a slice of buffers. Read more

Writes an entire buffer into the byte stream. Read more

Flushes the stream to ensure that all buffered contents reach their destination. Read more

Closes the writer. Read more

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

in order to support downcasting from a Box<dyn Transport>, Transport requires implementing an as_box_any function. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.