From a986fc07c4849ee3d7753c433a3dbace63a58ca9 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Wed, 29 Jan 2025 13:25:20 -0800 Subject: [PATCH] rename to transportread/transportwrite/transportreadext/transportext --- client/src/stream_provider.rs | 6 +++--- server/src/handle/wisp/wispnet.rs | 10 +++++----- server/src/route.rs | 2 +- simple-wisp-client/src/main.rs | 4 ++-- wisp/src/extensions/mod.rs | 10 +++++----- wisp/src/locked_sink.rs | 6 +++--- wisp/src/mux/client.rs | 12 ++++++------ wisp/src/mux/inner.rs | 14 +++++++------- wisp/src/mux/mod.rs | 20 ++++++++++---------- wisp/src/mux/server.rs | 16 ++++++++-------- wisp/src/packet.rs | 6 +++--- wisp/src/stream/compat.rs | 30 +++++++++++++++--------------- wisp/src/stream/handles.rs | 6 +++--- wisp/src/stream/mod.rs | 22 +++++++++++----------- wisp/src/ws/mod.rs | 16 ++++++++-------- wisp/src/ws/split.rs | 12 ++++++------ 16 files changed, 96 insertions(+), 96 deletions(-) diff --git a/client/src/stream_provider.rs b/client/src/stream_provider.rs index 5690c85..d37d477 100644 --- a/client/src/stream_provider.rs +++ b/client/src/stream_provider.rs @@ -19,7 +19,7 @@ use wisp_mux::{ extensions::{udp::UdpProtocolExtensionBuilder, AnyProtocolExtensionBuilder}, packet::StreamType, stream::{MuxStream, MuxStreamAsyncRW}, - ws::{WebSocketRead, WebSocketWrite}, + ws::{TransportRead, TransportWrite}, ClientMux, WispV2Handshake, }; @@ -33,8 +33,8 @@ pub type ProviderUnencryptedStream = MuxStream; pub type ProviderUnencryptedAsyncRW = MuxStreamAsyncRW; pub type ProviderTlsAsyncRW = IgnoreCloseNotify; pub type ProviderAsyncRW = Either; -pub type ProviderWispTransportRead = Pin>; -pub type ProviderWispTransportWrite = Pin>; +pub type ProviderWispTransportRead = Pin>; +pub type ProviderWispTransportWrite = Pin>; pub type ProviderWispTransportGenerator = Box< dyn Fn( bool, diff --git a/server/src/handle/wisp/wispnet.rs b/server/src/handle/wisp/wispnet.rs index 639c56b..5b1f075 100644 --- a/server/src/handle/wisp/wispnet.rs +++ b/server/src/handle/wisp/wispnet.rs @@ -17,7 +17,7 @@ use wisp_mux::{ }, packet::{CloseReason, ConnectPacket}, stream::{MuxStream, MuxStreamRead, MuxStreamWrite}, - ws::{WebSocketRead, WebSocketWrite}, + ws::{TransportRead, TransportWrite}, ClientMux, Role, WispError, WispV2Handshake, }; @@ -98,8 +98,8 @@ impl ProtocolExtension for WispnetServerProtocolExtension { async fn handle_handshake( &mut self, - _: &mut dyn WebSocketRead, - _: &mut dyn WebSocketWrite, + _: &mut dyn TransportRead, + _: &mut dyn TransportWrite, ) -> Result<(), WispError> { Ok(()) } @@ -108,8 +108,8 @@ impl ProtocolExtension for WispnetServerProtocolExtension { &mut self, packet_type: u8, mut packet: Bytes, - _: &mut dyn WebSocketRead, - write: &mut dyn WebSocketWrite, + _: &mut dyn TransportRead, + write: &mut dyn TransportWrite, ) -> Result<(), WispError> { if packet_type == Self::ID { if packet.remaining() < 4 { diff --git a/server/src/route.rs b/server/src/route.rs index 5395810..14a64bc 100644 --- a/server/src/route.rs +++ b/server/src/route.rs @@ -13,7 +13,7 @@ use log::{debug, error, trace}; use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; use tokio_websockets::Limits; use wisp_mux::ws::{ - TokioWebsocketsTransport, WebSocketExt, WebSocketSplitRead, WebSocketSplitWrite, + TokioWebsocketsTransport, TransportExt, WebSocketSplitRead, WebSocketSplitWrite, }; use crate::{ diff --git a/simple-wisp-client/src/main.rs b/simple-wisp-client/src/main.rs index 8697ab7..3e67f73 100644 --- a/simple-wisp-client/src/main.rs +++ b/simple-wisp-client/src/main.rs @@ -34,7 +34,7 @@ use wisp_mux::{ AnyProtocolExtensionBuilder, ProtocolExtensionListExt, }, packet::StreamType, - ws::{TokioWebsocketsTransport, WebSocketWrite, WebSocketExt}, + ws::{TokioWebsocketsTransport, TransportWrite, TransportExt}, ClientMux, WispError, WispV2Handshake, }; @@ -98,7 +98,7 @@ async fn create_mux( opts: &Cli, ) -> Result< ( - ClientMux, + ClientMux, impl Future> + Send, ), Box, diff --git a/wisp/src/extensions/mod.rs b/wisp/src/extensions/mod.rs index 7d46f46..4086b51 100644 --- a/wisp/src/extensions/mod.rs +++ b/wisp/src/extensions/mod.rs @@ -15,7 +15,7 @@ use async_trait::async_trait; use bytes::{BufMut, Bytes}; use crate::{ - ws::{PayloadMut, WebSocketRead, WebSocketWrite}, + ws::{PayloadMut, TransportRead, TransportWrite}, Role, WispError, }; @@ -112,8 +112,8 @@ pub trait ProtocolExtension: std::fmt::Debug + Sync + Send + 'static { /// This should be used to send or receive data before any streams are created. async fn handle_handshake( &mut self, - read: &mut dyn WebSocketRead, - write: &mut dyn WebSocketWrite, + read: &mut dyn TransportRead, + write: &mut dyn TransportWrite, ) -> Result<(), WispError> { let _ = (read, write); Ok(()) @@ -124,8 +124,8 @@ pub trait ProtocolExtension: std::fmt::Debug + Sync + Send + 'static { &mut self, packet_type: u8, packet: Bytes, - read: &mut dyn WebSocketRead, - write: &mut dyn WebSocketWrite, + read: &mut dyn TransportRead, + write: &mut dyn TransportWrite, ) -> Result<(), WispError> { let _ = (packet_type, packet, read, write); Ok(()) diff --git a/wisp/src/locked_sink.rs b/wisp/src/locked_sink.rs index ce27528..264230b 100644 --- a/wisp/src/locked_sink.rs +++ b/wisp/src/locked_sink.rs @@ -16,13 +16,13 @@ use std::{ use futures::Sink; use slab::Slab; -use crate::ws::{Payload, WebSocketWrite}; +use crate::ws::{Payload, TransportWrite}; // it would be nice to have type_alias_bounds but oh well #[expect(type_alias_bounds)] -pub(crate) type LockedWebSocketWrite = LockedSink; +pub(crate) type LockedWebSocketWrite = LockedSink; #[expect(type_alias_bounds)] -pub type LockedWebSocketWriteGuard = LockedSinkGuard; +pub type LockedWebSocketWriteGuard = LockedSinkGuard; pub(crate) enum Waiter { Sleeping(Waker), diff --git a/wisp/src/mux/client.rs b/wisp/src/mux/client.rs index a298551..afe21f2 100644 --- a/wisp/src/mux/client.rs +++ b/wisp/src/mux/client.rs @@ -5,7 +5,7 @@ use crate::{ mux::send_info_packet, packet::{ConnectPacket, ContinuePacket, MaybeInfoPacket, Packet, StreamType}, stream::MuxStream, - ws::{WebSocketRead, WebSocketReadExt, WebSocketWrite}, + ws::{TransportRead, TransportReadExt, TransportWrite}, LockedWebSocketWrite, Role, WispError, }; @@ -18,7 +18,7 @@ use super::{ pub(crate) struct ClientActor; -impl MultiplexorActor for ClientActor { +impl MultiplexorActor for ClientActor { fn handle_connect_packet( &mut self, _: crate::stream::MuxStream, @@ -54,10 +54,10 @@ impl MultiplexorActor for ClientActor { pub struct ClientImpl; -impl MultiplexorImpl for ClientImpl { +impl MultiplexorImpl for ClientImpl { type Actor = ClientActor; - async fn handshake( + async fn handshake( &mut self, rx: &mut R, tx: &mut LockedWebSocketWrite, @@ -126,14 +126,14 @@ impl MultiplexorImpl for ClientImpl { } } -impl Multiplexor { +impl Multiplexor { /// Create a new client side multiplexor. /// /// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created. /// **It is not guaranteed that all extensions you specify are available.** You must manually check /// if the extensions you need are available after the multiplexor has been created. #[expect(clippy::new_ret_no_self)] - pub async fn new( + pub async fn new( rx: R, tx: W, wisp_v2: Option, diff --git a/wisp/src/mux/inner.rs b/wisp/src/mux/inner.rs index 43e679c..a280529 100644 --- a/wisp/src/mux/inner.rs +++ b/wisp/src/mux/inner.rs @@ -22,11 +22,11 @@ use crate::{ PacketType, StreamType, }, stream::MuxStream, - ws::{Payload, WebSocketRead, WebSocketWrite}, + ws::{Payload, TransportRead, TransportWrite}, LockedWebSocketWrite, WispError, }; -pub(crate) enum WsEvent { +pub(crate) enum WsEvent { Close(u32, ClosePacket, oneshot::Sender>), CreateStream( ConnectPacket, @@ -135,7 +135,7 @@ impl StreamInfo { } } -pub(crate) trait MultiplexorActor: Send { +pub(crate) trait MultiplexorActor: Send { fn handle_connect_packet( &mut self, stream: MuxStream, @@ -164,14 +164,14 @@ pub(crate) trait MultiplexorActor: Send { fn get_flow_control(ty: StreamType, flow_stream_types: &[u8]) -> FlowControl; } -struct MuxStart { +struct MuxStart { rx: R, downgrade: Option>, extensions: Vec, actor_rx: flume::Receiver>, } -pub(crate) struct MuxInner> { +pub(crate) struct MuxInner> { start: Option>, tx: LockedWebSocketWrite, flow_stream_types: Box<[u8]>, @@ -185,12 +185,12 @@ pub(crate) struct MuxInner>, } -pub(crate) struct MuxInnerResult> { +pub(crate) struct MuxInnerResult> { pub mux: MuxInner, pub actor_tx: flume::Sender>, } -impl> MuxInner { +impl> MuxInner { #[expect(clippy::new_ret_no_self)] pub fn new( rx: R, diff --git a/wisp/src/mux/mod.rs b/wisp/src/mux/mod.rs index 8bbb7e0..3fb77aa 100644 --- a/wisp/src/mux/mod.rs +++ b/wisp/src/mux/mod.rs @@ -15,7 +15,7 @@ pub type ClientMux = Multiplexor; use crate::{ extensions::{udp::UdpProtocolExtension, AnyProtocolExtension, AnyProtocolExtensionBuilder}, packet::{CloseReason, InfoPacket, Packet, PacketType}, - ws::{WebSocketRead, WebSocketWrite}, + ws::{TransportRead, TransportWrite}, LockedWebSocketWrite, LockedWebSocketWriteGuard, Role, WispError, WISP_VERSION, }; @@ -43,7 +43,7 @@ impl WispHandshakeResultKind { } } -async fn handle_handshake( +async fn handle_handshake( read: &mut R, write: &mut LockedWebSocketWrite, extensions: &mut [AnyProtocolExtension], @@ -58,7 +58,7 @@ async fn handle_handshake( Ok(()) } -async fn send_info_packet( +async fn send_info_packet( write: &mut LockedWebSocketWrite, builders: &mut [AnyProtocolExtensionBuilder], role: Role, @@ -104,10 +104,10 @@ fn get_supported_extensions( .collect() } -trait MultiplexorImpl { +trait MultiplexorImpl { type Actor: MultiplexorActor + 'static; - async fn handshake( + async fn handshake( &mut self, rx: &mut R, tx: &mut LockedWebSocketWrite, @@ -122,7 +122,7 @@ trait MultiplexorImpl { } #[expect(private_bounds)] -pub struct Multiplexor, W: WebSocketWrite> { +pub struct Multiplexor, W: TransportWrite> { mux: M, downgraded: bool, @@ -133,7 +133,7 @@ pub struct Multiplexor, W: WebSocketWrite> { } #[expect(private_bounds)] -impl, W: WebSocketWrite> Multiplexor { +impl, W: TransportWrite> Multiplexor { async fn create( mut rx: R, tx: W, @@ -142,7 +142,7 @@ impl, W: WebSocketWrite> Multiplexor { actor: M::Actor, ) -> Result, WispError> where - R: WebSocketRead, + R: TransportRead, { let mut tx = LockedWebSocketWrite::new(tx); @@ -256,13 +256,13 @@ pub type MultiplexorActorFuture = Pin(Multiplexor, MultiplexorActorFuture) where M: MultiplexorImpl, - W: WebSocketWrite; + W: TransportWrite; #[expect(private_bounds)] impl MuxResult where M: MultiplexorImpl, - W: WebSocketWrite, + W: TransportWrite, { /// Require no protocol extensions. pub fn with_no_required_extensions(self) -> (Multiplexor, MultiplexorActorFuture) { diff --git a/wisp/src/mux/server.rs b/wisp/src/mux/server.rs index 46399aa..d1d6126 100644 --- a/wisp/src/mux/server.rs +++ b/wisp/src/mux/server.rs @@ -4,7 +4,7 @@ use crate::{ locked_sink::LockedWebSocketWrite, packet::{CloseReason, ConnectPacket, MaybeInfoPacket, Packet, StreamType}, stream::MuxStream, - ws::{Payload, WebSocketRead, WebSocketReadExt, WebSocketWrite}, + ws::{Payload, TransportRead, TransportReadExt, TransportWrite}, Role, WispError, }; @@ -15,11 +15,11 @@ use super::{ WispHandshakeResultKind, WispV2Handshake, }; -pub(crate) struct ServerActor { +pub(crate) struct ServerActor { stream_tx: flume::Sender<(ConnectPacket, MuxStream)>, } -impl MultiplexorActor for ServerActor { +impl MultiplexorActor for ServerActor { fn handle_connect_packet( &mut self, stream: MuxStream, @@ -62,15 +62,15 @@ impl MultiplexorActor for ServerActor { } } -pub struct ServerImpl { +pub struct ServerImpl { buffer_size: u32, stream_rx: flume::Receiver<(ConnectPacket, MuxStream)>, } -impl MultiplexorImpl for ServerImpl { +impl MultiplexorImpl for ServerImpl { type Actor = ServerActor; - async fn handshake( + async fn handshake( &mut self, rx: &mut R, tx: &mut LockedWebSocketWrite, @@ -165,14 +165,14 @@ impl MultiplexorImpl for ServerImpl { } } -impl Multiplexor, W> { +impl Multiplexor, W> { /// Create a new server-side multiplexor. /// /// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created. /// **It is not guaranteed that all extensions you specify are available.** You must manually check /// if the extensions you need are available after the multiplexor has been created. #[expect(clippy::new_ret_no_self)] - pub async fn new( + pub async fn new( rx: R, tx: W, buffer_size: u32, diff --git a/wisp/src/packet.rs b/wisp/src/packet.rs index 93650e5..0375081 100644 --- a/wisp/src/packet.rs +++ b/wisp/src/packet.rs @@ -5,7 +5,7 @@ use num_enum::{FromPrimitive, IntoPrimitive}; use crate::{ extensions::{AnyProtocolExtension, AnyProtocolExtensionBuilder}, - ws::{Payload, PayloadMut, PayloadRef, WebSocketRead, WebSocketWrite}, + ws::{Payload, PayloadMut, PayloadRef, TransportRead, TransportWrite}, LockedWebSocketWrite, Role, WispError, WISP_VERSION, }; @@ -404,10 +404,10 @@ pub(crate) enum MaybeExtensionPacket<'a> { } impl MaybeExtensionPacket<'static> { - pub(crate) async fn decode( + pub(crate) async fn decode( mut packet: Payload, extensions: &mut [AnyProtocolExtension], - rx: &mut dyn WebSocketRead, + rx: &mut dyn TransportRead, tx: &mut LockedWebSocketWrite, ) -> Result { if packet.remaining() < size_of::() + size_of::() { diff --git a/wisp/src/stream/compat.rs b/wisp/src/stream/compat.rs index e9d188f..5b61b89 100644 --- a/wisp/src/stream/compat.rs +++ b/wisp/src/stream/compat.rs @@ -14,15 +14,15 @@ use pin_project::pin_project; use crate::{ locked_sink::LockedWebSocketWrite, packet::{ClosePacket, CloseReason, Packet}, - ws::{Payload, WebSocketWrite}, + ws::{Payload, TransportWrite}, WispError, }; use super::{MuxStream, MuxStreamRead, MuxStreamWrite, StreamInfo, WsEvent}; -struct MapToIo(MuxStreamRead); +struct MapToIo(MuxStreamRead); -impl Stream for MapToIo { +impl Stream for MapToIo { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -32,12 +32,12 @@ impl Stream for MapToIo { // TODO: don't use `futures` for this so get_close_reason etc can be implemented #[pin_project] -pub struct MuxStreamAsyncRead { +pub struct MuxStreamAsyncRead { #[pin] inner: IntoAsyncRead>, } -impl MuxStreamAsyncRead { +impl MuxStreamAsyncRead { pub(crate) fn new(inner: MuxStreamRead) -> Self { Self { inner: MapToIo(inner).into_async_read(), @@ -45,7 +45,7 @@ impl MuxStreamAsyncRead { } } -impl AsyncRead for MuxStreamAsyncRead { +impl AsyncRead for MuxStreamAsyncRead { fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -63,7 +63,7 @@ impl AsyncRead for MuxStreamAsyncRead { } } -impl AsyncBufRead for MuxStreamAsyncRead { +impl AsyncBufRead for MuxStreamAsyncRead { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().inner.poll_fill_buf(cx) } @@ -73,7 +73,7 @@ impl AsyncBufRead for MuxStreamAsyncRead { } } -pub struct MuxStreamAsyncWrite { +pub struct MuxStreamAsyncWrite { inner: flume::r#async::SendSink<'static, WsEvent>, write: LockedWebSocketWrite, info: Arc, @@ -81,7 +81,7 @@ pub struct MuxStreamAsyncWrite { oneshot: Option>>, } -impl MuxStreamAsyncWrite { +impl MuxStreamAsyncWrite { pub(crate) fn new(inner: MuxStreamWrite) -> Self { Self { inner: inner.inner, @@ -98,7 +98,7 @@ impl MuxStreamAsyncWrite { } } -impl AsyncWrite for MuxStreamAsyncWrite { +impl AsyncWrite for MuxStreamAsyncWrite { fn poll_write( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -160,14 +160,14 @@ impl AsyncWrite for MuxStreamAsyncWrite { } #[pin_project] -pub struct MuxStreamAsyncRW { +pub struct MuxStreamAsyncRW { #[pin] read: MuxStreamAsyncRead, #[pin] write: MuxStreamAsyncWrite, } -impl MuxStreamAsyncRW { +impl MuxStreamAsyncRW { pub(crate) fn new(old: MuxStream) -> Self { Self { read: MuxStreamAsyncRead::new(old.read), @@ -185,7 +185,7 @@ impl MuxStreamAsyncRW { } } -impl AsyncRead for MuxStreamAsyncRW { +impl AsyncRead for MuxStreamAsyncRW { fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -203,7 +203,7 @@ impl AsyncRead for MuxStreamAsyncRW { } } -impl AsyncBufRead for MuxStreamAsyncRW { +impl AsyncBufRead for MuxStreamAsyncRW { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.project().read.poll_fill_buf(cx) } @@ -213,7 +213,7 @@ impl AsyncBufRead for MuxStreamAsyncRW { } } -impl AsyncWrite for MuxStreamAsyncRW { +impl AsyncWrite for MuxStreamAsyncRW { fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/wisp/src/stream/handles.rs b/wisp/src/stream/handles.rs index 9a8b4b7..c5e5741 100644 --- a/wisp/src/stream/handles.rs +++ b/wisp/src/stream/handles.rs @@ -4,7 +4,7 @@ use futures::channel::oneshot; use crate::{ packet::{ClosePacket, CloseReason}, - ws::WebSocketWrite, + ws::TransportWrite, WispError, }; @@ -12,12 +12,12 @@ use super::{StreamInfo, WsEvent}; /// Close handle for a multiplexor stream. #[derive(Clone)] -pub struct MuxStreamCloser { +pub struct MuxStreamCloser { pub(crate) info: Arc, pub(crate) inner: flume::Sender>, } -impl MuxStreamCloser { +impl MuxStreamCloser { /// Close the stream. You will no longer be able to write or read after this has been called. pub async fn close(&self, reason: CloseReason) -> Result<(), WispError> { if self.inner.is_disconnected() { diff --git a/wisp/src/stream/mod.rs b/wisp/src/stream/mod.rs index 9c26a68..1497ff8 100644 --- a/wisp/src/stream/mod.rs +++ b/wisp/src/stream/mod.rs @@ -9,7 +9,7 @@ use futures::{channel::oneshot, FutureExt, Sink, SinkExt, Stream, StreamExt}; use crate::{ mux::inner::{FlowControl, StreamInfo, WsEvent}, packet::{ClosePacket, CloseReason, Packet}, - ws::{Payload, WebSocketWrite}, + ws::{Payload, TransportWrite}, LockedWebSocketWrite, WispError, }; @@ -35,7 +35,7 @@ macro_rules! unlock { }; } -pub struct MuxStreamRead { +pub struct MuxStreamRead { inner: flume::r#async::RecvStream<'static, Payload>, write: LockedWebSocketWrite, info: Arc, @@ -44,7 +44,7 @@ pub struct MuxStreamRead { chunk: Option, } -impl MuxStreamRead { +impl MuxStreamRead { fn new( inner: flume::Receiver, write: LockedWebSocketWrite, @@ -73,7 +73,7 @@ impl MuxStreamRead { } } -impl Stream for MuxStreamRead { +impl Stream for MuxStreamRead { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -124,7 +124,7 @@ impl Stream for MuxStreamRead { } } -pub struct MuxStreamWrite { +pub struct MuxStreamWrite { inner: flume::r#async::SendSink<'static, WsEvent>, write: LockedWebSocketWrite, info: Arc, @@ -134,7 +134,7 @@ pub struct MuxStreamWrite { oneshot: Option>>, } -impl MuxStreamWrite { +impl MuxStreamWrite { fn new( inner: flume::Sender>, write: LockedWebSocketWrite, @@ -203,7 +203,7 @@ impl MuxStreamWrite { } } -impl Sink for MuxStreamWrite { +impl Sink for MuxStreamWrite { type Error = WispError; fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -277,12 +277,12 @@ impl Sink for MuxStreamWrite { } } -pub struct MuxStream { +pub struct MuxStream { read: MuxStreamRead, write: MuxStreamWrite, } -impl MuxStream { +impl MuxStream { pub(crate) fn new( rx: flume::Receiver, tx: flume::Sender>, @@ -321,7 +321,7 @@ impl MuxStream { } } -impl Stream for MuxStream { +impl Stream for MuxStream { type Item = as Stream>::Item; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -333,7 +333,7 @@ impl Stream for MuxStream { } } -impl Sink for MuxStream { +impl Sink for MuxStream { type Error = as Sink>::Error; fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { diff --git a/wisp/src/ws/mod.rs b/wisp/src/ws/mod.rs index 8152de6..31d196c 100644 --- a/wisp/src/ws/mod.rs +++ b/wisp/src/ws/mod.rs @@ -59,25 +59,25 @@ impl Deref for PayloadRef<'_> { pub type Payload = Bytes; pub type PayloadMut = BytesMut; -pub trait WebSocketRead: +pub trait TransportRead: Stream> + Send + Unpin + 'static { } -impl> + Send + Unpin + 'static> WebSocketRead for S {} +impl> + Send + Unpin + 'static> TransportRead for S {} -pub(crate) trait WebSocketReadExt: WebSocketRead { +pub(crate) trait TransportReadExt: TransportRead { async fn next_erroring(&mut self) -> Result { self.next().await.ok_or(WispError::WsImplSocketClosed)? } } -impl WebSocketReadExt for S {} +impl TransportReadExt for S {} -pub trait WebSocketWrite: Sink + Send + Unpin + 'static {} -impl + Send + Unpin + 'static> WebSocketWrite for S {} +pub trait TransportWrite: Sink + Send + Unpin + 'static {} +impl + Send + Unpin + 'static> TransportWrite for S {} -pub trait WebSocketExt: WebSocketRead + WebSocketWrite + Sized { +pub trait TransportExt: TransportRead + TransportWrite + Sized { fn split_fast(self) -> (WebSocketSplitRead, WebSocketSplitWrite) { split::split(self) } } -impl WebSocketExt for S {} +impl TransportExt for S {} diff --git a/wisp/src/ws/split.rs b/wisp/src/ws/split.rs index 0bdbbc3..b27440f 100644 --- a/wisp/src/ws/split.rs +++ b/wisp/src/ws/split.rs @@ -2,13 +2,13 @@ use std::sync::{Arc, Mutex, MutexGuard}; use futures::{Sink, SinkExt, Stream, StreamExt}; -use super::{WebSocketRead, WebSocketWrite}; +use super::{TransportRead, TransportWrite}; fn lock(mutex: &Mutex) -> MutexGuard<'_, T> { mutex.lock().expect("WebSocketSplit mutex was poisoned") } -pub(crate) fn split( +pub(crate) fn split( s: S, ) -> (WebSocketSplitRead, WebSocketSplitWrite) { let inner = Arc::new(Mutex::new(s)); @@ -19,9 +19,9 @@ pub(crate) fn split( ) } -pub struct WebSocketSplitRead(Arc>); +pub struct WebSocketSplitRead(Arc>); -impl Stream for WebSocketSplitRead { +impl Stream for WebSocketSplitRead { type Item = S::Item; fn poll_next( @@ -32,9 +32,9 @@ impl Stream for WebSocketSplitRead { } } -pub struct WebSocketSplitWrite(Arc>); +pub struct WebSocketSplitWrite(Arc>); -impl, T> Sink for WebSocketSplitWrite { +impl, T> Sink for WebSocketSplitWrite { type Error = >::Error; fn poll_ready(