mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-19 20:13:51 +00:00
Fix some clippy warnings
This commit is contained in:
parent
09f2c5fce1
commit
03d1910708
71 changed files with 172 additions and 132 deletions
|
@ -5,7 +5,7 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let mut args = std::env::args();
|
let mut args = std::env::args();
|
||||||
match (args.nth(1).as_ref().map(String::as_str), args.next()) {
|
match (args.nth(1).as_deref(), args.next()) {
|
||||||
(Some("client"), None) => client::main(),
|
(Some("client"), None) => client::main(),
|
||||||
(Some("server"), None) => server::main(),
|
(Some("server"), None) => server::main(),
|
||||||
_ => Err("Usage: a-chat [client|server]".into()),
|
_ => Err("Usage: a-chat [client|server]".into()),
|
||||||
|
|
|
@ -36,7 +36,8 @@ impl DirBuilder {
|
||||||
///
|
///
|
||||||
/// let builder = DirBuilder::new();
|
/// let builder = DirBuilder::new();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new() -> DirBuilder {
|
#[must_use]
|
||||||
|
pub const fn new() -> DirBuilder {
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
let builder = DirBuilder { recursive: false };
|
let builder = DirBuilder { recursive: false };
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ impl DirEntry {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn path(&self) -> PathBuf {
|
pub fn path(&self) -> PathBuf {
|
||||||
self.0.path().into()
|
self.0.path().into()
|
||||||
}
|
}
|
||||||
|
@ -147,6 +148,7 @@ impl DirEntry {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn file_name(&self) -> OsString {
|
pub fn file_name(&self) -> OsString {
|
||||||
self.0.file_name()
|
self.0.file_name()
|
||||||
}
|
}
|
||||||
|
|
|
@ -871,6 +871,7 @@ impl LockGuard<State> {
|
||||||
|
|
||||||
// This function does nothing because we're not sure about `AsyncWrite::poll_close()`'s exact
|
// This function does nothing because we're not sure about `AsyncWrite::poll_close()`'s exact
|
||||||
// semantics nor whether it will stay in the `AsyncWrite` trait.
|
// semantics nor whether it will stay in the `AsyncWrite` trait.
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
fn poll_close(self, _: &mut Context<'_>) -> Poll<io::Result<()>> {
|
fn poll_close(self, _: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
@ -899,7 +900,8 @@ mod tests {
|
||||||
drop(clone);
|
drop(clone);
|
||||||
buf.len()
|
buf.len()
|
||||||
})
|
})
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
assert_eq!(len as u64, file.metadata().await.unwrap().len());
|
assert_eq!(len as u64, file.metadata().await.unwrap().len());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ impl OpenOptions {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> OpenOptions {
|
pub fn new() -> OpenOptions {
|
||||||
OpenOptions(std::fs::OpenOptions::new())
|
OpenOptions(std::fs::OpenOptions::new())
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ enum State {
|
||||||
|
|
||||||
impl ReadDir {
|
impl ReadDir {
|
||||||
/// Creates an asynchronous `ReadDir` from a synchronous handle.
|
/// Creates an asynchronous `ReadDir` from a synchronous handle.
|
||||||
pub(crate) fn new(inner: std::fs::ReadDir) -> ReadDir {
|
pub(crate) const fn new(inner: std::fs::ReadDir) -> ReadDir {
|
||||||
ReadDir(State::Idle(Some(inner)))
|
ReadDir(State::Idle(Some(inner)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl<R> BufReader<R> {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_ref(&self) -> &R {
|
pub const fn get_ref(&self) -> &R {
|
||||||
&self.inner
|
&self.inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ impl<W: Write> BufWriter<W> {
|
||||||
self.project().inner
|
self.project().inner
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes BufWriter, returning the underlying writer
|
/// Consumes `BufWriter`, returning the underlying writer
|
||||||
///
|
///
|
||||||
/// This method will not write leftover data, it will be lost.
|
/// This method will not write leftover data, it will be lost.
|
||||||
/// For method that will attempt to write before returning the writer see [`poll_into_inner`]
|
/// For method that will attempt to write before returning the writer see [`poll_into_inner`]
|
||||||
|
@ -263,7 +263,7 @@ impl<W: Write> BufWriter<W> {
|
||||||
|
|
||||||
/// Poll buffer flushing until completion
|
/// Poll buffer flushing until completion
|
||||||
///
|
///
|
||||||
/// This is used in types that wrap around BufWrite, one such example: [`LineWriter`]
|
/// This is used in types that wrap around `BufWrite`, one such example: [`LineWriter`]
|
||||||
///
|
///
|
||||||
/// [`LineWriter`]: struct.LineWriter.html
|
/// [`LineWriter`]: struct.LineWriter.html
|
||||||
fn poll_flush_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
fn poll_flush_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||||
|
|
|
@ -22,7 +22,8 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn empty() -> Empty {
|
#[must_use]
|
||||||
|
pub const fn empty() -> Empty {
|
||||||
Empty { _private: () }
|
Empty { _private: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
//! nickname: readers and writers. So you'll sometimes see 'a reader' instead
|
//! nickname: readers and writers. So you'll sometimes see 'a reader' instead
|
||||||
//! of 'a type that implements the [`Read`] trait'. Much easier!
|
//! of 'a type that implements the [`Read`] trait'. Much easier!
|
||||||
//!
|
//!
|
||||||
//! ## Seek and BufRead
|
//! ## `Seek` and `BufRead`
|
||||||
//!
|
//!
|
||||||
//! Beyond that, there are two important traits that are provided: [`Seek`]
|
//! Beyond that, there are two important traits that are provided: [`Seek`]
|
||||||
//! and [`BufRead`]. Both of these build on top of a reader to control
|
//! and [`BufRead`]. Both of these build on top of a reader to control
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
//! [`BufRead`] uses an internal buffer to provide a number of other ways to read, but
|
//! [`BufRead`] uses an internal buffer to provide a number of other ways to read, but
|
||||||
//! to show it off, we'll need to talk about buffers in general. Keep reading!
|
//! to show it off, we'll need to talk about buffers in general. Keep reading!
|
||||||
//!
|
//!
|
||||||
//! ## BufReader and BufWriter
|
//! ## `BufReader` and `BufWriter`
|
||||||
//!
|
//!
|
||||||
//! Byte-based interfaces are unwieldy and can be inefficient, as we'd need to be
|
//! Byte-based interfaces are unwieldy and can be inefficient, as we'd need to be
|
||||||
//! making near-constant calls to the operating system. To help with this,
|
//! making near-constant calls to the operating system. To help with this,
|
||||||
|
@ -214,7 +214,7 @@
|
||||||
//!
|
//!
|
||||||
//! [functions-list]: #functions-1
|
//! [functions-list]: #functions-1
|
||||||
//!
|
//!
|
||||||
//! ## io::Result
|
//! ## `io::Result`
|
||||||
//!
|
//!
|
||||||
//! Last, but certainly not least, is [`io::Result`]. This type is used
|
//! Last, but certainly not least, is [`io::Result`]. This type is used
|
||||||
//! as the return type of many `std::io` functions that can cause an error, and
|
//! as the return type of many `std::io` functions that can cause an error, and
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl<T, U> Chain<T, U> {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_ref(&self) -> (&T, &U) {
|
pub const fn get_ref(&self) -> (&T, &U) {
|
||||||
(&self.first, &self.second)
|
(&self.first, &self.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,10 +157,10 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
||||||
|
|
||||||
fn consume(self: Pin<&mut Self>, amt: usize) {
|
fn consume(self: Pin<&mut Self>, amt: usize) {
|
||||||
let this = self.project();
|
let this = self.project();
|
||||||
if !*this.done_first {
|
if *this.done_first {
|
||||||
this.first.consume(amt)
|
|
||||||
} else {
|
|
||||||
this.second.consume(amt)
|
this.second.consume(amt)
|
||||||
|
} else {
|
||||||
|
this.first.consume(amt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,7 +485,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_read_by_ref() {
|
fn test_read_by_ref() {
|
||||||
crate::task::block_on(async {
|
crate::task::block_on(async {
|
||||||
let mut f = io::Cursor::new(vec![0u8, 1, 2, 3, 4, 5, 6, 7, 8]);
|
let mut f = io::Cursor::new(vec![0_u8, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
let mut other_buffer = Vec::new();
|
let mut other_buffer = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl<T> Take<T> {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn limit(&self) -> u64 {
|
pub const fn limit(&self) -> u64 {
|
||||||
self.limit
|
self.limit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ mod tests {
|
||||||
let source: io::Cursor<Vec<u8>> = io::Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
let source: io::Cursor<Vec<u8>> = io::Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
|
|
||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
let mut buffer = [0u8; 5];
|
let mut buffer = [0_u8; 5];
|
||||||
|
|
||||||
// read at most five bytes
|
// read at most five bytes
|
||||||
let mut handle = source.take(5);
|
let mut handle = source.take(5);
|
||||||
|
|
|
@ -23,7 +23,8 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn repeat(byte: u8) -> Repeat {
|
#[must_use]
|
||||||
|
pub const fn repeat(byte: u8) -> Repeat {
|
||||||
Repeat { byte }
|
Repeat { byte }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn sink() -> Sink {
|
#[must_use]
|
||||||
|
pub const fn sink() -> Sink {
|
||||||
Sink { _private: () }
|
Sink { _private: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::future::Future;
|
|
||||||
|
|
||||||
use crate::io::{self, Write};
|
use crate::io::{self, Write};
|
||||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||||
|
@ -30,6 +30,7 @@ use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn stderr() -> Stderr {
|
pub fn stderr() -> Stderr {
|
||||||
Stderr(Mutex::new(State::Idle(Some(Inner {
|
Stderr(Mutex::new(State::Idle(Some(Inner {
|
||||||
stderr: std::io::stderr(),
|
stderr: std::io::stderr(),
|
||||||
|
@ -150,7 +151,7 @@ impl Write for Stderr {
|
||||||
// Check if the operation has completed.
|
// Check if the operation has completed.
|
||||||
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
||||||
return Poll::Ready(res);
|
return Poll::Ready(res);
|
||||||
} else {
|
}
|
||||||
let mut inner = opt.take().unwrap();
|
let mut inner = opt.take().unwrap();
|
||||||
|
|
||||||
// Start the operation asynchronously.
|
// Start the operation asynchronously.
|
||||||
|
@ -160,7 +161,6 @@ impl Write for Stderr {
|
||||||
State::Idle(Some(inner))
|
State::Idle(Some(inner))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Poll the asynchronous operation the stderr is currently blocked on.
|
// Poll the asynchronous operation the stderr is currently blocked on.
|
||||||
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ use crate::utils::Context as _;
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn stdin() -> Stdin {
|
pub fn stdin() -> Stdin {
|
||||||
Stdin(Mutex::new(State::Idle(Some(Inner {
|
Stdin(Mutex::new(State::Idle(Some(Inner {
|
||||||
stdin: std::io::stdin(),
|
stdin: std::io::stdin(),
|
||||||
|
@ -125,7 +126,7 @@ impl Stdin {
|
||||||
// Copy the read data into the buffer and return.
|
// Copy the read data into the buffer and return.
|
||||||
buf.push_str(&inner.line);
|
buf.push_str(&inner.line);
|
||||||
return Poll::Ready(Ok(n));
|
return Poll::Ready(Ok(n));
|
||||||
} else {
|
}
|
||||||
let mut inner = opt.take().unwrap();
|
let mut inner = opt.take().unwrap();
|
||||||
|
|
||||||
// Start the operation asynchronously.
|
// Start the operation asynchronously.
|
||||||
|
@ -136,7 +137,6 @@ impl Stdin {
|
||||||
State::Idle(Some(inner))
|
State::Idle(Some(inner))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Poll the asynchronous operation the stdin is currently blocked on.
|
// Poll the asynchronous operation the stdin is currently blocked on.
|
||||||
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::future::Future;
|
|
||||||
|
|
||||||
use crate::io::{self, Write};
|
use crate::io::{self, Write};
|
||||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||||
|
@ -30,6 +30,7 @@ use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn stdout() -> Stdout {
|
pub fn stdout() -> Stdout {
|
||||||
Stdout(Mutex::new(State::Idle(Some(Inner {
|
Stdout(Mutex::new(State::Idle(Some(Inner {
|
||||||
stdout: std::io::stdout(),
|
stdout: std::io::stdout(),
|
||||||
|
@ -150,7 +151,7 @@ impl Write for Stdout {
|
||||||
// Check if the operation has completed.
|
// Check if the operation has completed.
|
||||||
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
||||||
return Poll::Ready(res);
|
return Poll::Ready(res);
|
||||||
} else {
|
}
|
||||||
let mut inner = opt.take().unwrap();
|
let mut inner = opt.take().unwrap();
|
||||||
|
|
||||||
// Start the operation asynchronously.
|
// Start the operation asynchronously.
|
||||||
|
@ -160,7 +161,6 @@ impl Write for Stdout {
|
||||||
State::Idle(Some(inner))
|
State::Idle(Some(inner))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Poll the asynchronous operation the stdout is currently blocked on.
|
// Poll the asynchronous operation the stdout is currently blocked on.
|
||||||
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ where
|
||||||
let this = self.project();
|
let this = self.project();
|
||||||
match this.future.poll(cx) {
|
match this.future.poll(cx) {
|
||||||
Poll::Pending => {}
|
Poll::Pending => {}
|
||||||
other => return other,
|
other @ Poll::Ready(..) => return other,
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.timeout.poll(cx).is_ready() {
|
if this.timeout.poll(cx).is_ready() {
|
||||||
|
|
|
@ -146,6 +146,7 @@ impl TcpListener {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn incoming(&self) -> Incoming<'_> {
|
pub fn incoming(&self) -> Incoming<'_> {
|
||||||
Incoming {
|
Incoming {
|
||||||
listener: self,
|
listener: self,
|
||||||
|
|
|
@ -127,6 +127,7 @@ impl UnixListener {
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn incoming(&self) -> Incoming<'_> {
|
pub fn incoming(&self) -> Incoming<'_> {
|
||||||
Incoming {
|
Incoming {
|
||||||
listener: self,
|
listener: self,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::path::Path;
|
||||||
///
|
///
|
||||||
/// [`ancestors`]: struct.Path.html#method.ancestors
|
/// [`ancestors`]: struct.Path.html#method.ancestors
|
||||||
/// [`Path`]: struct.Path.html
|
/// [`Path`]: struct.Path.html
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Ancestors<'a> {
|
pub struct Ancestors<'a> {
|
||||||
pub(crate) next: Option<&'a Path>,
|
pub(crate) next: Option<&'a Path>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ impl<'a> Components<'a> {
|
||||||
///
|
///
|
||||||
/// assert_eq!(Path::new("foo/bar.txt"), components.as_path());
|
/// assert_eq!(Path::new("foo/bar.txt"), components.as_path());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn as_path(&self) -> &'a Path {
|
pub fn as_path(&self) -> &'a Path {
|
||||||
self.inner.as_path().into()
|
self.inner.as_path().into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl<'a> Iter<'a> {
|
||||||
///
|
///
|
||||||
/// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
|
/// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_path(&self) -> &'a Path {
|
#[must_use] pub fn as_path(&self) -> &'a Path {
|
||||||
self.inner.as_path()
|
self.inner.as_path()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ impl Path {
|
||||||
/// let os_str = Path::new("foo.txt").as_os_str();
|
/// let os_str = Path::new("foo.txt").as_os_str();
|
||||||
/// assert_eq!(os_str, OsStr::new("foo.txt"));
|
/// assert_eq!(os_str, OsStr::new("foo.txt"));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn as_os_str(&self) -> &OsStr {
|
pub fn as_os_str(&self) -> &OsStr {
|
||||||
self.inner.as_os_str()
|
self.inner.as_os_str()
|
||||||
}
|
}
|
||||||
|
@ -111,6 +112,7 @@ impl Path {
|
||||||
/// let path = Path::new("foo.txt");
|
/// let path = Path::new("foo.txt");
|
||||||
/// assert_eq!(path.to_str(), Some("foo.txt"));
|
/// assert_eq!(path.to_str(), Some("foo.txt"));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn to_str(&self) -> Option<&str> {
|
pub fn to_str(&self) -> Option<&str> {
|
||||||
self.inner.to_str()
|
self.inner.to_str()
|
||||||
}
|
}
|
||||||
|
@ -136,6 +138,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
|
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
|
||||||
/// have returned `"fo<66>.txt"`.
|
/// have returned `"fo<66>.txt"`.
|
||||||
|
#[must_use]
|
||||||
pub fn to_string_lossy(&self) -> Cow<'_, str> {
|
pub fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
self.inner.to_string_lossy()
|
self.inner.to_string_lossy()
|
||||||
}
|
}
|
||||||
|
@ -152,6 +155,7 @@ impl Path {
|
||||||
/// let path_buf = Path::new("foo.txt").to_path_buf();
|
/// let path_buf = Path::new("foo.txt").to_path_buf();
|
||||||
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
|
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn to_path_buf(&self) -> PathBuf {
|
pub fn to_path_buf(&self) -> PathBuf {
|
||||||
PathBuf::from(self.inner.to_path_buf())
|
PathBuf::from(self.inner.to_path_buf())
|
||||||
}
|
}
|
||||||
|
@ -174,6 +178,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// assert!(!Path::new("foo.txt").is_absolute());
|
/// assert!(!Path::new("foo.txt").is_absolute());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn is_absolute(&self) -> bool {
|
pub fn is_absolute(&self) -> bool {
|
||||||
self.inner.is_absolute()
|
self.inner.is_absolute()
|
||||||
}
|
}
|
||||||
|
@ -191,6 +196,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// assert!(Path::new("foo.txt").is_relative());
|
/// assert!(Path::new("foo.txt").is_relative());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn is_relative(&self) -> bool {
|
pub fn is_relative(&self) -> bool {
|
||||||
self.inner.is_relative()
|
self.inner.is_relative()
|
||||||
}
|
}
|
||||||
|
@ -211,6 +217,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// assert!(Path::new("/etc/passwd").has_root());
|
/// assert!(Path::new("/etc/passwd").has_root());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn has_root(&self) -> bool {
|
pub fn has_root(&self) -> bool {
|
||||||
self.inner.has_root()
|
self.inner.has_root()
|
||||||
}
|
}
|
||||||
|
@ -234,6 +241,7 @@ impl Path {
|
||||||
/// assert_eq!(grand_parent, Path::new("/"));
|
/// assert_eq!(grand_parent, Path::new("/"));
|
||||||
/// assert_eq!(grand_parent.parent(), None);
|
/// assert_eq!(grand_parent.parent(), None);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn parent(&self) -> Option<&Path> {
|
pub fn parent(&self) -> Option<&Path> {
|
||||||
self.inner.parent().map(|p| p.into())
|
self.inner.parent().map(|p| p.into())
|
||||||
}
|
}
|
||||||
|
@ -260,7 +268,8 @@ impl Path {
|
||||||
/// assert_eq!(ancestors.next(), Some(Path::new("/").into()));
|
/// assert_eq!(ancestors.next(), Some(Path::new("/").into()));
|
||||||
/// assert_eq!(ancestors.next(), None);
|
/// assert_eq!(ancestors.next(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn ancestors(&self) -> Ancestors<'_> {
|
#[must_use]
|
||||||
|
pub const fn ancestors(&self) -> Ancestors<'_> {
|
||||||
Ancestors { next: Some(&self) }
|
Ancestors { next: Some(&self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +296,7 @@ impl Path {
|
||||||
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
|
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
|
||||||
/// assert_eq!(None, Path::new("/").file_name());
|
/// assert_eq!(None, Path::new("/").file_name());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn file_name(&self) -> Option<&OsStr> {
|
pub fn file_name(&self) -> Option<&OsStr> {
|
||||||
self.inner.file_name()
|
self.inner.file_name()
|
||||||
}
|
}
|
||||||
|
@ -387,6 +397,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// assert_eq!("foo", path.file_stem().unwrap());
|
/// assert_eq!("foo", path.file_stem().unwrap());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn file_stem(&self) -> Option<&OsStr> {
|
pub fn file_stem(&self) -> Option<&OsStr> {
|
||||||
self.inner.file_stem()
|
self.inner.file_stem()
|
||||||
}
|
}
|
||||||
|
@ -412,6 +423,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// assert_eq!("rs", path.extension().unwrap());
|
/// assert_eq!("rs", path.extension().unwrap());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn extension(&self) -> Option<&OsStr> {
|
pub fn extension(&self) -> Option<&OsStr> {
|
||||||
self.inner.extension()
|
self.inner.extension()
|
||||||
}
|
}
|
||||||
|
@ -510,6 +522,7 @@ impl Path {
|
||||||
/// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
|
/// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
|
||||||
/// assert_eq!(components.next(), None);
|
/// assert_eq!(components.next(), None);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn components(&self) -> Components<'_> {
|
pub fn components(&self) -> Components<'_> {
|
||||||
Components {
|
Components {
|
||||||
inner: self.inner.components(),
|
inner: self.inner.components(),
|
||||||
|
@ -538,6 +551,7 @@ impl Path {
|
||||||
/// assert_eq!(it.next(), Some(OsStr::new("foo.txt")));
|
/// assert_eq!(it.next(), Some(OsStr::new("foo.txt")));
|
||||||
/// assert_eq!(it.next(), None)
|
/// assert_eq!(it.next(), None)
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn iter(&self) -> Iter<'_> {
|
pub fn iter(&self) -> Iter<'_> {
|
||||||
Iter {
|
Iter {
|
||||||
inner: self.components(),
|
inner: self.components(),
|
||||||
|
@ -558,6 +572,7 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// println!("{}", path.display());
|
/// println!("{}", path.display());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn display(&self) -> Display<'_> {
|
pub fn display(&self) -> Display<'_> {
|
||||||
self.inner.display()
|
self.inner.display()
|
||||||
}
|
}
|
||||||
|
@ -719,7 +734,7 @@ impl Path {
|
||||||
/// # See Also
|
/// # See Also
|
||||||
///
|
///
|
||||||
/// This is a convenience function that coerces errors to false. If you want to
|
/// This is a convenience function that coerces errors to false. If you want to
|
||||||
/// check errors, call [fs::metadata].
|
/// check errors, call [`fs::metadata`].
|
||||||
///
|
///
|
||||||
/// [fs::metadata]: ../fs/fn.metadata.html
|
/// [fs::metadata]: ../fs/fn.metadata.html
|
||||||
#[cfg(not(target_os = "unknown"))]
|
#[cfg(not(target_os = "unknown"))]
|
||||||
|
@ -750,8 +765,8 @@ impl Path {
|
||||||
/// # See Also
|
/// # See Also
|
||||||
///
|
///
|
||||||
/// This is a convenience function that coerces errors to false. If you want to
|
/// This is a convenience function that coerces errors to false. If you want to
|
||||||
/// check errors, call [fs::metadata] and handle its Result. Then call
|
/// check errors, call [`fs::metadata`] and handle its Result. Then call
|
||||||
/// [fs::Metadata::is_file] if it was Ok.
|
/// [`fs::Metadata::is_file`] if it was Ok.
|
||||||
///
|
///
|
||||||
/// [fs::metadata]: ../fs/fn.metadata.html
|
/// [fs::metadata]: ../fs/fn.metadata.html
|
||||||
/// [fs::Metadata::is_file]: ../fs/struct.Metadata.html#method.is_file
|
/// [fs::Metadata::is_file]: ../fs/struct.Metadata.html#method.is_file
|
||||||
|
@ -787,8 +802,8 @@ impl Path {
|
||||||
/// # See Also
|
/// # See Also
|
||||||
///
|
///
|
||||||
/// This is a convenience function that coerces errors to false. If you want to
|
/// This is a convenience function that coerces errors to false. If you want to
|
||||||
/// check errors, call [fs::metadata] and handle its Result. Then call
|
/// check errors, call [`fs::metadata`] and handle its Result. Then call
|
||||||
/// [fs::Metadata::is_dir] if it was Ok.
|
/// [`fs::Metadata::is_dir`] if it was Ok.
|
||||||
///
|
///
|
||||||
/// [fs::metadata]: ../fs/fn.metadata.html
|
/// [fs::metadata]: ../fs/fn.metadata.html
|
||||||
/// [fs::Metadata::is_dir]: ../fs/struct.Metadata.html#method.is_dir
|
/// [fs::Metadata::is_dir]: ../fs/struct.Metadata.html#method.is_dir
|
||||||
|
@ -814,6 +829,7 @@ impl Path {
|
||||||
/// let path: Box<Path> = Path::new("foo.txt").into();
|
/// let path: Box<Path> = Path::new("foo.txt").into();
|
||||||
/// let path_buf = path.into_path_buf();
|
/// let path_buf = path.into_path_buf();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
|
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
|
||||||
let rw = Box::into_raw(self) as *mut std::path::Path;
|
let rw = Box::into_raw(self) as *mut std::path::Path;
|
||||||
let inner = unsafe { Box::from_raw(rw) };
|
let inner = unsafe { Box::from_raw(rw) };
|
||||||
|
@ -1015,9 +1031,9 @@ impl<'a> From<&'a std::path::Path> for &'a Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Into<&'a std::path::Path> for &'a Path {
|
impl<'a> From<&'a Path> for &'a std::path::Path {
|
||||||
fn into(self) -> &'a std::path::Path {
|
fn from(path: &'a Path) -> &'a std::path::Path {
|
||||||
std::path::Path::new(&self.inner)
|
std::path::Path::new(&path.inner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ impl PathBuf {
|
||||||
///
|
///
|
||||||
/// let path = PathBuf::new();
|
/// let path = PathBuf::new();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> PathBuf {
|
pub fn new() -> PathBuf {
|
||||||
std::path::PathBuf::new().into()
|
std::path::PathBuf::new().into()
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,7 @@ impl PathBuf {
|
||||||
/// let p = PathBuf::from("/test");
|
/// let p = PathBuf::from("/test");
|
||||||
/// assert_eq!(Path::new("/test"), p.as_path());
|
/// assert_eq!(Path::new("/test"), p.as_path());
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn as_path(&self) -> &Path {
|
pub fn as_path(&self) -> &Path {
|
||||||
self.inner.as_path().into()
|
self.inner.as_path().into()
|
||||||
}
|
}
|
||||||
|
@ -182,6 +184,7 @@ impl PathBuf {
|
||||||
/// let p = PathBuf::from("/the/head");
|
/// let p = PathBuf::from("/the/head");
|
||||||
/// let os_str = p.into_os_string();
|
/// let os_str = p.into_os_string();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
pub fn into_os_string(self) -> OsString {
|
pub fn into_os_string(self) -> OsString {
|
||||||
self.inner.into_os_string()
|
self.inner.into_os_string()
|
||||||
}
|
}
|
||||||
|
@ -190,6 +193,7 @@ impl PathBuf {
|
||||||
///
|
///
|
||||||
/// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
|
/// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
|
||||||
/// [`Path`]: struct.Path.html
|
/// [`Path`]: struct.Path.html
|
||||||
|
#[must_use]
|
||||||
pub fn into_boxed_path(self) -> Box<Path> {
|
pub fn into_boxed_path(self) -> Box<Path> {
|
||||||
let rw = Box::into_raw(self.inner.into_boxed_path()) as *mut Path;
|
let rw = Box::into_raw(self.inner.into_boxed_path()) as *mut Path;
|
||||||
unsafe { Box::from_raw(rw) }
|
unsafe { Box::from_raw(rw) }
|
||||||
|
@ -271,7 +275,7 @@ impl Deref for PathBuf {
|
||||||
|
|
||||||
impl Borrow<Path> for PathBuf {
|
impl Borrow<Path> for PathBuf {
|
||||||
fn borrow(&self) -> &Path {
|
fn borrow(&self) -> &Path {
|
||||||
self.deref()
|
&*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,9 +368,9 @@ impl From<std::path::PathBuf> for PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<std::path::PathBuf> for PathBuf {
|
impl From<PathBuf> for std::path::PathBuf {
|
||||||
fn into(self) -> std::path::PathBuf {
|
fn from(path_buf: PathBuf) -> std::path::PathBuf {
|
||||||
self.inner
|
path_buf.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # })
|
/// # })
|
||||||
/// ```
|
/// ```
|
||||||
pub fn empty<T>() -> Empty<T> {
|
#[must_use]
|
||||||
|
pub const fn empty<T>() -> Empty<T> {
|
||||||
Empty {
|
Empty {
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@
|
||||||
//! can call `next()` on your stream, until it reaches `None`. Let's go over
|
//! can call `next()` on your stream, until it reaches `None`. Let's go over
|
||||||
//! that next.
|
//! that next.
|
||||||
//!
|
//!
|
||||||
//! # while let Loops and IntoStream
|
//! # while let Loops and `IntoStream`
|
||||||
//!
|
//!
|
||||||
//! Rust's `while let` loop syntax is an idiomatic way to iterate over streams. Here's a basic
|
//! Rust's `while let` loop syntax is an idiomatic way to iterate over streams. Here's a basic
|
||||||
//! example of `while let`:
|
//! example of `while let`:
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::stream::DoubleEndedStream;
|
||||||
/// #
|
/// #
|
||||||
/// # })
|
/// # })
|
||||||
/// ```
|
/// ```
|
||||||
pub fn once<T>(t: T) -> Once<T> {
|
pub const fn once<T>(t: T) -> Once<T> {
|
||||||
Once { value: Some(t) }
|
Once { value: Some(t) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Cloned<S> {
|
impl<S> Cloned<S> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self { stream }
|
Self { stream }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl<L: Stream, R: Stream> CmpFuture<L, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for CmpFuture<L, R>
|
impl<L, R> Future for CmpFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream<Item = L::Item> + Sized,
|
R: Stream<Item = L::Item> + Sized,
|
||||||
|
|
|
@ -13,7 +13,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Copied<S> {
|
impl<S> Copied<S> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self { stream }
|
Self { stream }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ where
|
||||||
this.source.set(this.orig.clone());
|
this.source.set(this.orig.clone());
|
||||||
this.source.poll_next(cx)
|
this.source.poll_next(cx)
|
||||||
}
|
}
|
||||||
item => Poll::Ready(item),
|
item @ Some(..) => Poll::Ready(item),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Enumerate<S> {
|
impl<S> Enumerate<S> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self { stream, i: 0 }
|
Self { stream, i: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for EqFuture<L, R>
|
impl<L, R> Future for EqFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, P> Filter<S, P> {
|
impl<S, P> Filter<S, P> {
|
||||||
pub(super) fn new(stream: S, predicate: P) -> Self {
|
pub(super) const fn new(stream: S, predicate: P) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
predicate,
|
predicate,
|
||||||
|
|
|
@ -15,7 +15,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F> FilterMap<S, F> {
|
impl<S, F> FilterMap<S, F> {
|
||||||
pub(crate) fn new(stream: S, f: F) -> Self {
|
pub(crate) const fn new(stream: S, f: F) -> Self {
|
||||||
Self { stream, f }
|
Self { stream, f }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,13 @@ where
|
||||||
let this = self.project();
|
let this = self.project();
|
||||||
let next = futures_core::ready!(this.stream.poll_next(cx));
|
let next = futures_core::ready!(this.stream.poll_next(cx));
|
||||||
match next {
|
match next {
|
||||||
Some(v) => match (this.f)(v) {
|
Some(v) => (this.f)(v).map_or_else(
|
||||||
Some(b) => Poll::Ready(Some(b)),
|
|| {
|
||||||
None => {
|
|
||||||
cx.waker().wake_by_ref();
|
cx.waker().wake_by_ref();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|b| Poll::Ready(Some(b)),
|
||||||
|
),
|
||||||
None => Poll::Ready(None),
|
None => Poll::Ready(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ where
|
||||||
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
|
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
|
||||||
|
|
||||||
match item {
|
match item {
|
||||||
Some(v) => match (&mut self.f)(v) {
|
Some(v) => (&mut self.f)(v).map_or_else(
|
||||||
Some(v) => Poll::Ready(Some(v)),
|
|| {
|
||||||
None => {
|
|
||||||
cx.waker().wake_by_ref();
|
cx.waker().wake_by_ref();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|v| Poll::Ready(Some(v)),
|
||||||
|
),
|
||||||
None => Poll::Ready(None),
|
None => Poll::Ready(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F, B> FoldFuture<S, F, B> {
|
impl<S, F, B> FoldFuture<S, F, B> {
|
||||||
pub(super) fn new(stream: S, init: B, f: F) -> Self {
|
pub(super) const fn new(stream: S, init: B, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F> ForEachFuture<S, F> {
|
impl<S, F> ForEachFuture<S, F> {
|
||||||
pub(super) fn new(stream: S, f: F) -> Self {
|
pub(super) const fn new(stream: S, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Fuse<S> {
|
impl<S> Fuse<S> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
done: false,
|
done: false,
|
||||||
|
|
|
@ -31,7 +31,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for GeFuture<L, R>
|
impl<L, R> Future for GeFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream,
|
L: Stream,
|
||||||
R: Stream,
|
R: Stream,
|
||||||
|
|
|
@ -31,7 +31,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for GtFuture<L, R>
|
impl<L, R> Future for GtFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F> Inspect<S, F> {
|
impl<S, F> Inspect<S, F> {
|
||||||
pub(super) fn new(stream: S, f: F) -> Self {
|
pub(super) const fn new(stream: S, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> LastFuture<S, T> {
|
impl<S, T> LastFuture<S, T> {
|
||||||
pub(crate) fn new(stream: S) -> Self {
|
pub(crate) const fn new(stream: S) -> Self {
|
||||||
Self { stream, last: None }
|
Self { stream, last: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for LeFuture<L, R>
|
impl<L, R> Future for LeFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -31,7 +31,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for LtFuture<L, R>
|
impl<L, R> Future for LtFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -16,7 +16,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F> Map<S, F> {
|
impl<S, F> Map<S, F> {
|
||||||
pub(crate) fn new(stream: S, f: F) -> Self {
|
pub(crate) const fn new(stream: S, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -18,7 +18,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> MaxFuture<S, T> {
|
impl<S, T> MaxFuture<S, T> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self { stream, max: None }
|
Self { stream, max: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F, T> MaxByFuture<S, F, T> {
|
impl<S, F, T> MaxByFuture<S, F, T> {
|
||||||
pub(super) fn new(stream: S, compare: F) -> Self {
|
pub(super) const fn new(stream: S, compare: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
compare,
|
compare,
|
||||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T, K> MaxByKeyFuture<S, T, K> {
|
impl<S, T, K> MaxByKeyFuture<S, T, K> {
|
||||||
pub(super) fn new(stream: S, key_by: K) -> Self {
|
pub(super) const fn new(stream: S, key_by: K) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
max: None,
|
max: None,
|
||||||
|
|
|
@ -18,7 +18,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> MinFuture<S, T> {
|
impl<S, T> MinFuture<S, T> {
|
||||||
pub(super) fn new(stream: S) -> Self {
|
pub(super) const fn new(stream: S) -> Self {
|
||||||
Self { stream, min: None }
|
Self { stream, min: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, F, T> MinByFuture<S, F, T> {
|
impl<S, F, T> MinByFuture<S, F, T> {
|
||||||
pub(super) fn new(stream: S, compare: F) -> Self {
|
pub(super) const fn new(stream: S, compare: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
compare,
|
compare,
|
||||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T, K> MinByKeyFuture<S, T, K> {
|
impl<S, T, K> MinByKeyFuture<S, T, K> {
|
||||||
pub(super) fn new(stream: S, key_by: K) -> Self {
|
pub(super) const fn new(stream: S, key_by: K) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
min: None,
|
min: None,
|
||||||
|
|
|
@ -33,7 +33,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for NeFuture<L, R>
|
impl<L, R> Future for NeFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use core::future::Future;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
use core::future::Future;
|
|
||||||
|
|
||||||
use crate::stream::Stream;
|
use crate::stream::Stream;
|
||||||
|
|
||||||
|
@ -28,14 +28,15 @@ where
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let next = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
|
let next = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
|
||||||
match next {
|
match next {
|
||||||
Some(v) => match self.n {
|
Some(v) => {
|
||||||
0 => Poll::Ready(Some(v)),
|
if let 0 = self.n {
|
||||||
_ => {
|
Poll::Ready(Some(v))
|
||||||
|
} else {
|
||||||
self.n -= 1;
|
self.n -= 1;
|
||||||
cx.waker().wake_by_ref();
|
cx.waker().wake_by_ref();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => Poll::Ready(None),
|
None => Poll::Ready(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl<L: Stream, R: Stream> PartialCmpFuture<L, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Stream, R: Stream> Future for PartialCmpFuture<L, R>
|
impl<L, R> Future for PartialCmpFuture<L, R>
|
||||||
where
|
where
|
||||||
L: Stream + Sized,
|
L: Stream + Sized,
|
||||||
R: Stream + Sized,
|
R: Stream + Sized,
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, St, F> Scan<S, St, F> {
|
impl<S, St, F> Scan<S, St, F> {
|
||||||
pub(crate) fn new(stream: S, initial_state: St, f: F) -> Self {
|
pub(crate) const fn new(stream: S, initial_state: St, f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
state_f: (initial_state, f),
|
state_f: (initial_state, f),
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Skip<S> {
|
impl<S> Skip<S> {
|
||||||
pub(crate) fn new(stream: S, n: usize) -> Self {
|
pub(crate) const fn new(stream: S, n: usize) -> Self {
|
||||||
Self { stream, n }
|
Self { stream, n }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, P> SkipWhile<S, P> {
|
impl<S, P> SkipWhile<S, P> {
|
||||||
pub(crate) fn new(stream: S, predicate: P) -> Self {
|
pub(crate) const fn new(stream: S, predicate: P) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
predicate: Some(predicate),
|
predicate: Some(predicate),
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Take<S> {
|
impl<S> Take<S> {
|
||||||
pub(super) fn new(stream: S, remaining: usize) -> Self {
|
pub(super) const fn new(stream: S, remaining: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
remaining,
|
remaining,
|
||||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, P> TakeWhile<S, P> {
|
impl<S, P> TakeWhile<S, P> {
|
||||||
pub(super) fn new(stream: S, predicate: P) -> Self {
|
pub(super) const fn new(stream: S, predicate: P) -> Self {
|
||||||
Self {
|
Self {
|
||||||
stream,
|
stream,
|
||||||
predicate,
|
predicate,
|
||||||
|
|
|
@ -17,12 +17,14 @@ pub struct Builder {
|
||||||
impl Builder {
|
impl Builder {
|
||||||
/// Creates a new builder.
|
/// Creates a new builder.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> Builder {
|
#[must_use]
|
||||||
|
pub const fn new() -> Builder {
|
||||||
Builder { name: None }
|
Builder { name: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configures the name of the task.
|
/// Configures the name of the task.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub fn name(mut self, name: String) -> Builder {
|
pub fn name(mut self, name: String) -> Builder {
|
||||||
self.name = Some(name);
|
self.name = Some(name);
|
||||||
self
|
self
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::task::{Task, TaskLocalsWrapper};
|
||||||
/// #
|
/// #
|
||||||
/// # })
|
/// # })
|
||||||
/// ```
|
/// ```
|
||||||
pub fn current() -> Task {
|
#[must_use] pub fn current() -> Task {
|
||||||
TaskLocalsWrapper::get_current(|t| t.task().clone())
|
TaskLocalsWrapper::get_current(|t| t.task().clone())
|
||||||
.expect("`task::current()` called outside the context of a task")
|
.expect("`task::current()` called outside the context of a task")
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,8 @@ impl<T> JoinHandle<T> {
|
||||||
/// println!("id = {}", handle.task().id());
|
/// println!("id = {}", handle.task().id());
|
||||||
/// #
|
/// #
|
||||||
/// # })
|
/// # })
|
||||||
pub fn task(&self) -> &Task {
|
#[must_use]
|
||||||
|
pub const fn task(&self) -> &Task {
|
||||||
&self.task
|
&self.task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl Task {
|
||||||
|
|
||||||
/// Gets the task's unique identifier.
|
/// Gets the task's unique identifier.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn id(&self) -> TaskId {
|
#[must_use] pub const fn id(&self) -> TaskId {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ impl Task {
|
||||||
/// The name is configured by [`Builder::name`] before spawning.
|
/// The name is configured by [`Builder::name`] before spawning.
|
||||||
///
|
///
|
||||||
/// [`Builder::name`]: struct.Builder.html#method.name
|
/// [`Builder::name`]: struct.Builder.html#method.name
|
||||||
|
#[must_use]
|
||||||
pub fn name(&self) -> Option<&str> {
|
pub fn name(&self) -> Option<&str> {
|
||||||
self.name.as_ref().map(|s| s.as_str())
|
self.name.as_ref().map(|s| s.as_str())
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl<T: Send + 'static> LocalKey<T> {
|
||||||
let value: *const dyn Send = task.locals().get_or_insert(key, init);
|
let value: *const dyn Send = task.locals().get_or_insert(key, init);
|
||||||
|
|
||||||
// Call the closure with the value passed as an argument.
|
// Call the closure with the value passed as an argument.
|
||||||
f(&*(value as *const T))
|
f(&*value.cast::<T>())
|
||||||
})
|
})
|
||||||
.ok_or(AccessError { _private: () })
|
.ok_or(AccessError { _private: () })
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ pub(crate) struct LocalsMap {
|
||||||
|
|
||||||
impl LocalsMap {
|
impl LocalsMap {
|
||||||
/// Creates an empty map of task-locals.
|
/// Creates an empty map of task-locals.
|
||||||
pub fn new() -> LocalsMap {
|
pub const fn new() -> LocalsMap {
|
||||||
LocalsMap {
|
LocalsMap {
|
||||||
entries: UnsafeCell::new(Some(Vec::new())),
|
entries: UnsafeCell::new(Some(Vec::new())),
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl TaskLocalsWrapper {
|
||||||
/// If the task is unnamed, the inner representation of the task will be lazily allocated on
|
/// If the task is unnamed, the inner representation of the task will be lazily allocated on
|
||||||
/// demand.
|
/// demand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn new(task: Task) -> Self {
|
pub(crate) const fn new(task: Task) -> Self {
|
||||||
Self {
|
Self {
|
||||||
task,
|
task,
|
||||||
locals: LocalsMap::new(),
|
locals: LocalsMap::new(),
|
||||||
|
@ -33,17 +33,17 @@ impl TaskLocalsWrapper {
|
||||||
|
|
||||||
/// Gets the task's unique identifier.
|
/// Gets the task's unique identifier.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn id(&self) -> TaskId {
|
pub const fn id(&self) -> TaskId {
|
||||||
self.task.id()
|
self.task.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the inner `Task`.
|
/// Returns a reference to the inner `Task`.
|
||||||
pub(crate) fn task(&self) -> &Task {
|
pub(crate) const fn task(&self) -> &Task {
|
||||||
&self.task
|
&self.task
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the map holding task-local values.
|
/// Returns the map holding task-local values.
|
||||||
pub(crate) fn locals(&self) -> &LocalsMap {
|
pub(crate) const fn locals(&self) -> &LocalsMap {
|
||||||
&self.locals
|
&self.locals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,12 @@ impl Future for YieldNow {
|
||||||
// does is re-schedule the future back to the end of the queue, giving room
|
// does is re-schedule the future back to the end of the queue, giving room
|
||||||
// for other futures to progress.
|
// for other futures to progress.
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
if !self.0 {
|
if self.0 {
|
||||||
|
Poll::Ready(())
|
||||||
|
} else {
|
||||||
self.0 = true;
|
self.0 = true;
|
||||||
cx.waker().wake_by_ref();
|
cx.waker().wake_by_ref();
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
} else {
|
|
||||||
Poll::Ready(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ fn smoke() {
|
||||||
let lock = RwLock::new(());
|
let lock = RwLock::new(());
|
||||||
drop(lock.read().await);
|
drop(lock.read().await);
|
||||||
drop(lock.write().await);
|
drop(lock.write().await);
|
||||||
drop((lock.read().await, lock.read().await));
|
drop(lock.read().await);
|
||||||
|
drop(lock.read().await);
|
||||||
drop(lock.write().await);
|
drop(lock.write().await);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use async_std::io;
|
use async_std::io;
|
||||||
use async_std::os::unix::net::{UnixDatagram, UnixListener, UnixStream};
|
use async_std::os::unix::net::{UnixDatagram, UnixListener, UnixStream};
|
||||||
|
use async_std::path::Path;
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ fn socket_ping_pong() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let client_handle = std::thread::spawn(move || {
|
let client_handle = std::thread::spawn(move || {
|
||||||
task::block_on(async { ping_pong_client(&sock_path, iter_cnt).await }).unwrap()
|
task::block_on(async { ping_pong_client(&sock_path.as_ref(), iter_cnt).await }).unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
client_handle.join().unwrap();
|
client_handle.join().unwrap();
|
||||||
|
@ -102,10 +103,10 @@ async fn ping_pong_server(listener: UnixListener, iterations: u32) -> std::io::R
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ping_pong_client(socket: &std::path::PathBuf, iterations: u32) -> std::io::Result<()> {
|
async fn ping_pong_client(socket: &Path, iterations: u32) -> std::io::Result<()> {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
for _ix in 0..iterations {
|
for _ix in 0..iterations {
|
||||||
let mut socket = UnixStream::connect(&socket).await?;
|
let mut socket = UnixStream::connect(socket).await?;
|
||||||
socket.write_all(&PING).await?;
|
socket.write_all(&PING).await?;
|
||||||
let n = async_std::io::timeout(TEST_TIMEOUT, socket.read(&mut buf[..])).await?;
|
let n = async_std::io::timeout(TEST_TIMEOUT, socket.read(&mut buf[..])).await?;
|
||||||
assert_eq!(&buf[..n], PONG);
|
assert_eq!(&buf[..n], PONG);
|
||||||
|
|
Loading…
Reference in a new issue