Struct trillium_http::transport::BoxedTransport
source · [−]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
sourceimpl BoxedTransport
impl BoxedTransport
sourcepub fn new(t: impl Transport + 'static) -> Self
pub fn new(t: impl Transport + 'static) -> Self
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());
sourcepub fn downcast<T: 'static>(self) -> Option<Box<T>>
pub fn downcast<T: 'static>(self) -> Option<Box<T>>
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
Trait Implementations
sourceimpl AsyncRead for BoxedTransport
impl AsyncRead for BoxedTransport
sourceimpl AsyncWrite for BoxedTransport
impl AsyncWrite for BoxedTransport
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from
buf
into the object. Read moresourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempt to flush the object, ensuring that any buffered data reach
their destination. Read more
sourceimpl Debug for BoxedTransport
impl Debug for BoxedTransport
Auto Trait Implementations
impl !RefUnwindSafe for BoxedTransport
impl Send for BoxedTransport
impl Sync for BoxedTransport
impl Unpin for BoxedTransport
impl !UnwindSafe for BoxedTransport
Blanket Implementations
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
Reads some bytes from the byte stream. Read more
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
Reads the exact number of bytes required to fill
buf
. Read morefn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
Creates an adapter which will read at most
limit
bytes from it. Read moreimpl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
Writes some bytes into the byte stream. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
Writes an entire buffer into the byte stream. Read more
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Transport for Twhere
T: Any + AsyncRead + AsyncWrite + Send + Sync + Unpin,
impl<T> Transport for Twhere
T: Any + AsyncRead + AsyncWrite + Send + Sync + Unpin,
sourcefn as_box_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global>where
R: Read + ?Sized,impl<W> Write for Box<W, Global>where
W: Write + ?Sized,impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
fn as_box_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>impl<R> Read for Box<R, Global>where
R: Read + ?Sized,impl<W> Write for Box<W, Global>where
W: Write + ?Sized,impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
R: Read + ?Sized,impl<W> Write for Box<W, Global>where
W: Write + ?Sized,impl<F, A> Future for Box<F, A>where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A>where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
in order to support downcasting from a
Box<dyn Transport>
,
Transport requires implementing an as_box_any
function. Read more