Struct trillium_http::transport::BoxedTransport
source · pub struct BoxedTransport(/* private fields */);
Expand description
A type for dyn Transport
trait objects
BoxedTransport
represents a Box<dyn Transport + Any>
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§
source§impl BoxedTransport
impl BoxedTransport
sourcepub fn new<T: Transport + Any>(t: T) -> Self
pub fn new<T: Transport + Any>(t: T) -> 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
sourcepub fn downcast_ref<T: Transport>(&self) -> Option<&T>
pub fn downcast_ref<T: Transport>(&self) -> Option<&T>
Attempt to get a reference to the trait object as a specific transport type T. This will only
succeed if T is the type that was originally passed to BoxedTransport::new
, and will return
None otherwise
sourcepub fn downcast_mut<T: Transport>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: Transport>(&mut self) -> Option<&mut T>
Attempt to get a mutable reference to the trait object as a specific transport type T. This
will only succeed if T is the type that was originally passed to BoxedTransport::new
, and
will return None otherwise
Trait Implementations§
source§impl AsyncRead for BoxedTransportwhere
Self: Unpin,
impl AsyncRead for BoxedTransportwhere
Self: Unpin,
source§impl AsyncWrite for BoxedTransportwhere
Self: Unpin,
impl AsyncWrite for BoxedTransportwhere
Self: Unpin,
source§fn 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>>
buf
into the object. Read moresource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
source§impl Debug for BoxedTransport
impl Debug for BoxedTransport
source§impl Deref for BoxedTransport
impl Deref for BoxedTransport
source§impl Transport for BoxedTransport
impl Transport for BoxedTransport
source§fn set_linger(&mut self, linger: Option<Duration>) -> Result<()>
fn set_linger(&mut self, linger: Option<Duration>) -> Result<()>
SO_LINGER
option Read moresource§fn set_nodelay(&mut self, nodelay: bool) -> Result<()>
fn set_nodelay(&mut self, nodelay: bool) -> Result<()>
TCP_NODELAY
option on this transport. Read moreAuto 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>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read more§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read more