Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
added #[must_use] for impl Future structs (#31)
Browse files Browse the repository at this point in the history
* added #[must_use] for impl Future structs

* rustfmt applied

* added rusfmt.toml with unstable_features enabled

* added text to must_use
  • Loading branch information
ibaryshnikov authored and yoshuawuyts committed May 15, 2019
1 parent a0af792 commit 51e45c6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/guessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn main() -> Result<(), failure::Error> {

let mut incoming = listener.incoming();
while let Some(stream) = incoming.next().await {
runtime::spawn(play(stream?));
runtime::spawn(play(stream?)).await?;
}
Ok(())
}
3 changes: 2 additions & 1 deletion examples/tcp-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async fn main() -> std::io::Result<()> {
let (reader, writer) = &mut stream.split();
reader.copy_into(writer).await?;
Ok::<(), std::io::Error>(())
});
})
.await?;
}
Ok(())
}
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unstable_features = true
3 changes: 3 additions & 0 deletions src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl AsyncWrite for TcpStream {
///
/// [`TcpStream::connect`]: struct.TcpStream.html#method.connect
/// [`TcpStream`]: struct.TcpStream.html
#[must_use = "futures do nothing unless polled"]
pub struct Connect {
addrs: Option<io::Result<VecDeque<SocketAddr>>>,
last_err: Option<io::Error>,
Expand Down Expand Up @@ -452,6 +453,7 @@ impl TcpListener {
///
/// [`TcpStream::accept`]: struct.TcpStream.html#method.accept
/// [`TcpStream`]: struct.TcpStream.html
#[must_use = "futures do nothing unless polled"]
#[derive(Debug)]
pub struct Accept<'stream> {
inner: Incoming<'stream>,
Expand Down Expand Up @@ -479,6 +481,7 @@ impl<'stream> Future for Accept<'stream> {
/// [`incoming`]: struct.TcpListener.html#method.incoming
/// [`accept`]: struct.TcpStream.html#method.accept
/// [`TcpListener`]: struct.TcpStream.html
#[must_use = "streams do nothing unless polled"]
#[derive(Debug)]
pub struct Incoming<'listener> {
inner: &'listener mut TcpListener,
Expand Down
2 changes: 2 additions & 0 deletions src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl UdpSocket {
/// On success, returns the number of bytes written.
///
/// [`UdpSocket::send_to`]: struct.UdpSocket.html#method.send_to
#[must_use = "futures do nothing unless polled"]
#[derive(Debug)]
pub struct SendTo<'socket, 'buf> {
/// The open socket we use to send the message from.
Expand Down Expand Up @@ -392,6 +393,7 @@ impl<'socket, 'buf> Future for SendTo<'socket, 'buf> {
/// On success, returns the number of bytes read and the origin.
///
/// [`UdpSocket::recv_from`]: struct.UdpSocket.html#method.recv_from
#[must_use = "futures do nothing unless polled"]
#[derive(Debug)]
pub struct RecvFrom<'socket, 'buf> {
socket: &'socket mut UdpSocket,
Expand Down
1 change: 1 addition & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where
/// A handle that awaits the result of a [`spawn`]ed future.
///
/// [`spawn`]: fn.spawn.html
#[must_use = "futures do nothing unless polled"]
#[derive(Debug)]
pub struct JoinHandle<T> {
pub(crate) rx: futures::channel::oneshot::Receiver<T>,
Expand Down

0 comments on commit 51e45c6

Please sign in to comment.