-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove futures from ws_stream_wasm module (#111)
In #107 I removed futures in favour of futures-lite in various places. However, because ws_stream_wasm is not a default feature I didn't notice that I'd not removed futures from there as well. CI also did not catch this because futures was used for the tungstenite feature, which is often always on. This PR removes futures entirely, by implementing our own copy of StreamExt::send based on the futures impl, and then making sure there's no remaining uses of futures in the crate.
- Loading branch information
Showing
10 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
use futures_lite::ready; | ||
use futures_sink::Sink; | ||
|
||
/// A very limited clone of futures::SinkExt to avoid having to pull the original in | ||
pub trait SinkExt<Item>: Sink<Item> { | ||
fn send(&mut self, item: Item) -> Send<'_, Self, Item> | ||
where | ||
Self: Unpin, | ||
{ | ||
Send::new(self, item) | ||
} | ||
} | ||
|
||
impl<Item, T> SinkExt<Item> for T where T: Sink<Item> {} | ||
|
||
#[derive(Debug)] | ||
#[must_use = "futures do nothing unless you `.await` or poll them"] | ||
pub struct Send<'a, Si: ?Sized, Item> { | ||
sink: &'a mut Si, | ||
item: Option<Item>, | ||
} | ||
|
||
// Pinning is never projected to children | ||
impl<Si: Unpin + ?Sized, Item> Unpin for Send<'_, Si, Item> {} | ||
|
||
impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Send<'a, Si, Item> { | ||
pub(super) fn new(sink: &'a mut Si, item: Item) -> Self { | ||
Self { | ||
sink, | ||
item: Some(item), | ||
} | ||
} | ||
} | ||
|
||
impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Send<'_, Si, Item> { | ||
type Output = Result<(), Si::Error>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.get_mut(); | ||
let mut sink = Pin::new(&mut this.sink); | ||
|
||
if let Some(item) = this.item.take() { | ||
ready!(sink.as_mut().poll_ready(cx))?; | ||
sink.as_mut().start_send(item)?; | ||
} | ||
|
||
// we're done sending the item, but want to block on flushing the | ||
// sink | ||
ready!(sink.poll_flush(cx))?; | ||
|
||
Poll::Ready(Ok(())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters