pub struct WebTransportSession { /* private fields */ }Available on (crate features
http1 or http2 or http3) and crate feature http3 and crate feature webtransport only.Expand description
A WebTransport session handle.
This type provides access to bidirectional and unidirectional streams for a WebTransport session established over HTTP/3.
The session can be retrieved from the request extensions when handling a WebTransport CONNECT request.
§Example
ⓘ
async fn handle_webtransport(req: IncomingRequest) -> Result<Response<()>, std::convert::Infallible> {
if let Some(session) = req.extensions().get::<WebTransportSession>() {
// Handle WebTransport session
tokio::spawn({
let session = session.clone();
async move {
while let Ok(Some(accepted)) = session.accept_bi().await {
// Handle bidirectional streams
}
}
});
return Ok(Response::builder()
.status(200)
.body(())
.unwrap());
}
Ok(Response::builder()
.status(404)
.body(())
.unwrap())
}Implementations§
Source§impl WebTransportSession
impl WebTransportSession
Sourcepub async fn accept_bi(&self) -> Result<Option<AcceptedBi>, StreamError>
pub async fn accept_bi(&self) -> Result<Option<AcceptedBi>, StreamError>
Accept the next incoming bidirectional stream or request.
Returns None when the session is closed or no more streams are available.
§Example
ⓘ
async fn handle_session(session: WebTransportSession) {
while let Ok(Some(accepted)) = session.accept_bi().await {
match accepted {
AcceptedBi::BidiStream(stream) => {
// Handle raw bidirectional stream
}
AcceptedBi::Request(req, stream) => {
// Handle HTTP request over WebTransport
}
}
}
}Sourcepub async fn accept_uni(
&self,
) -> Result<Option<(WebTransportStreamId, WebTransportRecvStream)>, ConnectionError>
pub async fn accept_uni( &self, ) -> Result<Option<(WebTransportStreamId, WebTransportRecvStream)>, ConnectionError>
Accept the next incoming unidirectional stream.
Returns None when the session is closed or no more streams are available.
Sourcepub async fn open_bi(
&self,
) -> Result<(WebTransportSendStream, WebTransportRecvStream), StreamError>
pub async fn open_bi( &self, ) -> Result<(WebTransportSendStream, WebTransportRecvStream), StreamError>
Sourcepub async fn open_uni(&self) -> Result<WebTransportSendStream, StreamError>
pub async fn open_uni(&self) -> Result<WebTransportSendStream, StreamError>
Sourcepub fn session_id(&self) -> SessionId
pub fn session_id(&self) -> SessionId
Get the session ID for this WebTransport session.
Sourcepub fn datagram_sender(
&self,
) -> DatagramSender<<Connection as DatagramConnectionExt<Bytes>>::SendDatagramHandler, Bytes>
pub fn datagram_sender( &self, ) -> DatagramSender<<Connection as DatagramConnectionExt<Bytes>>::SendDatagramHandler, Bytes>
Sourcepub fn datagram_reader(
&self,
) -> DatagramReader<<Connection as DatagramConnectionExt<Bytes>>::RecvDatagramHandler>
pub fn datagram_reader( &self, ) -> DatagramReader<<Connection as DatagramConnectionExt<Bytes>>::RecvDatagramHandler>
Trait Implementations§
Source§impl Clone for WebTransportSession
impl Clone for WebTransportSession
Source§fn clone(&self) -> WebTransportSession
fn clone(&self) -> WebTransportSession
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WebTransportSession
impl !RefUnwindSafe for WebTransportSession
impl Send for WebTransportSession
impl Sync for WebTransportSession
impl Unpin for WebTransportSession
impl !UnwindSafe for WebTransportSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more