diff --git a/Cargo.toml b/Cargo.toml index 094dae16..34ae7add 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ futures-lite = { version = "2.0.0", optional = true } async-process = { version = "2.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -gloo-timers = { version = "0.2.1", features = ["futures"], optional = true } +gloo-timers = { version = "0.3.0", features = ["futures"], optional = true } wasm-bindgen-futures = { version = "0.4.10", optional = true } futures-channel = { version = "0.3.4", optional = true } diff --git a/examples/a-chat/server.rs b/examples/a-chat/server.rs index e049a490..d3ac7469 100644 --- a/examples/a-chat/server.rs +++ b/examples/a-chat/server.rs @@ -96,6 +96,7 @@ async fn connection_writer_loop( None => break, }, void = shutdown.next().fuse() => match void { + #[allow(unreachable_patterns)] Some(void) => match void {}, None => break, } diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index 47187b23..9a8bfcc1 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -27,6 +27,7 @@ pub use core::future::Future as Future; [`Future`]: ../future/trait.Future.html "#] +#[cfg(any(feature = "std", feature = "docs"))] pub trait FutureExt: Future { /// Returns a Future that delays execution for a specified time. /// @@ -284,5 +285,6 @@ pub trait FutureExt: Future { } } +#[cfg(any(feature = "std", feature = "docs"))] impl FutureExt for T {} diff --git a/src/io/buf_writer.rs b/src/io/buf_writer.rs index c972937f..230954e8 100644 --- a/src/io/buf_writer.rs +++ b/src/io/buf_writer.rs @@ -114,7 +114,7 @@ pin_project! { /// # Ok(()) }) } ///``` #[derive(Debug)] -pub struct IntoInnerError(W, crate::io::Error); +pub struct IntoInnerError(W, #[allow(dead_code)] crate::io::Error); impl BufWriter { /// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KB, diff --git a/src/io/read/bytes.rs b/src/io/read/bytes.rs index ab925961..786fdaa5 100644 --- a/src/io/read/bytes.rs +++ b/src/io/read/bytes.rs @@ -32,7 +32,7 @@ impl Stream for Bytes { } } -#[cfg(all(test, default))] +#[cfg(all(test, feature = "default", not(target_arch = "wasm32")))] mod tests { use crate::io; use crate::prelude::*; diff --git a/src/io/read/chain.rs b/src/io/read/chain.rs index 4fcdb0ec..b5eac581 100644 --- a/src/io/read/chain.rs +++ b/src/io/read/chain.rs @@ -165,7 +165,7 @@ impl BufRead for Chain { } } -#[cfg(all(test, default))] +#[cfg(all(test, feature = "default", not(target_arch = "wasm32")))] mod tests { use crate::io; use crate::prelude::*; diff --git a/src/io/stderr.rs b/src/io/stderr.rs index ca8d23d5..81cc197b 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -204,11 +204,13 @@ cfg_windows! { } cfg_io_safety! { - use crate::os::unix::io::{AsHandle, BorrowedHandle}; + use crate::os::windows::io::{AsHandle, BorrowedHandle}; impl AsHandle for Stderr { fn as_handle(&self) -> BorrowedHandle<'_> { - std::io::stderr().as_handle() + unsafe { + BorrowedHandle::borrow_raw(std::io::stderr().as_raw_handle()) + } } } } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index b994bcd0..d8f96d49 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -230,11 +230,13 @@ cfg_windows! { } cfg_io_safety! { - use crate::os::unix::io::{AsFd, BorrowedFd}; + use crate::os::windows::io::{AsHandle, BorrowedHandle}; - impl AsFd for Stdin { - fn as_fd(&self) -> BorrowedFd<'_> { - std::io::stdin().as_fd() + impl AsHandle for Stdin { + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { + BorrowedHandle::borrow_raw(std::io::stdin().as_raw_handle()) + } } } } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 2444bbd7..3cc570dc 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -204,11 +204,13 @@ cfg_windows! { } cfg_io_safety! { - use crate::os::unix::io::{AsHandle, BorrowedHandle}; + use crate::os::windows::io::{AsHandle, BorrowedHandle}; impl AsHandle for Stdout { fn as_handle(&self) -> BorrowedHandle<'_> { - std::io::stdout().as_handle() + unsafe { + BorrowedHandle::borrow_raw(std::io::stdout().as_raw_handle()) + } } } } diff --git a/src/lib.rs b/src/lib.rs index 86786e81..48eaa069 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,8 +284,6 @@ #![doc(test(attr(allow(unused_extern_crates, unused_variables))))] #![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")] -extern crate alloc; - #[macro_use] mod utils; diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index a6cbc927..3311f904 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -477,13 +477,13 @@ cfg_windows! { impl From for TcpStream { fn from(fd: OwnedSocket) -> TcpStream { - std::net::TcpListener::from(fd).into() + std::net::TcpStream::from(fd).into() } } impl From for OwnedSocket { fn from(stream: TcpStream) -> OwnedSocket { - stream.watcher.into_inner().unwrap().into() + stream.watcher.get_ref().try_clone().unwrap().into() } } } diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 7c8798f5..3bb2c6e9 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -620,7 +620,7 @@ cfg_windows! { impl From for UdpSocket { fn from(fd: OwnedSocket) -> UdpSocket { - std::net::TcpListener::from(fd).into() + std::net::UdpSocket::from(fd).into() } } diff --git a/src/stream/mod.rs b/src/stream/mod.rs index f7f2727a..8dd7d633 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -34,12 +34,17 @@ //! [`Stream`] looks like this: //! //! ``` +//! #![allow(dead_code)] //! # use async_std::task::{Context, Poll}; //! # use std::pin::Pin; -//! trait Stream { +//! pub trait Stream { //! type Item; //! fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll>; //! } +//! # impl Stream for () { +//! # type Item = (); +//! # fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Poll::Pending } +//! # } //! ``` //! //! A stream has a method, [`next`], which when called, returns an diff --git a/src/utils.rs b/src/utils.rs index 853ace0e..d1cb063b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,3 @@ -use alloc::string::String; - /// Calls a function and aborts if it panics. /// /// This is useful in unsafe code where we can't recover from panics. @@ -55,6 +53,7 @@ pub fn random(n: u32) -> u32 { } /// Add additional context to errors +#[cfg(feature = "std")] pub(crate) trait Context { fn context(self, message: impl Fn() -> String) -> Self; } @@ -148,7 +147,7 @@ macro_rules! cfg_unstable_default { ($($item:item)*) => { $( #[cfg(all(feature = "default", feature = "unstable"))] - #[cfg_attr(feature = "docs", doc(unstable))] + #[cfg_attr(feature = "docs", doc(cfg(unstable)))] $item )* } @@ -161,7 +160,6 @@ macro_rules! cfg_unix { ($($item:item)*) => { $( #[cfg(any(unix, feature = "docs"))] - #[cfg_attr(feature = "docs", doc(cfg(unix)))] $item )* } @@ -174,7 +172,6 @@ macro_rules! cfg_windows { ($($item:item)*) => { $( #[cfg(any(windows, feature = "docs"))] - #[cfg_attr(feature = "docs", doc(cfg(windows)))] $item )* }