mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-08 09:26:42 +00:00
Merge 5e30d86108
into 96f564672a
This commit is contained in:
commit
48c2ad2206
71 changed files with 172 additions and 130 deletions
|
@ -5,7 +5,7 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>
|
|||
|
||||
fn main() -> Result<()> {
|
||||
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("server"), None) => server::main(),
|
||||
_ => Err("Usage: a-chat [client|server]".into()),
|
||||
|
|
|
@ -36,7 +36,8 @@ impl DirBuilder {
|
|||
///
|
||||
/// let builder = DirBuilder::new();
|
||||
/// ```
|
||||
pub fn new() -> DirBuilder {
|
||||
#[must_use]
|
||||
pub const fn new() -> DirBuilder {
|
||||
#[cfg(not(unix))]
|
||||
let builder = DirBuilder { recursive: false };
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ impl DirEntry {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn path(&self) -> PathBuf {
|
||||
self.0.path().into()
|
||||
}
|
||||
|
@ -147,6 +148,7 @@ impl DirEntry {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn file_name(&self) -> OsString {
|
||||
self.0.file_name()
|
||||
}
|
||||
|
|
|
@ -949,6 +949,7 @@ impl LockGuard<State> {
|
|||
|
||||
// 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.
|
||||
#[allow(clippy::unused_self)]
|
||||
fn poll_close(self, _: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
@ -977,7 +978,8 @@ mod tests {
|
|||
drop(clone);
|
||||
buf.len()
|
||||
})
|
||||
}).await;
|
||||
})
|
||||
.await;
|
||||
assert_eq!(len as u64, file.metadata().await.unwrap().len());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ impl OpenOptions {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn new() -> OpenOptions {
|
||||
OpenOptions(std::fs::OpenOptions::new())
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ enum State {
|
|||
|
||||
impl ReadDir {
|
||||
/// 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)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ impl<R> BufReader<R> {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn get_ref(&self) -> &R {
|
||||
pub const fn get_ref(&self) -> &R {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ impl<W: Write> BufWriter<W> {
|
|||
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.
|
||||
/// 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
|
||||
///
|
||||
/// 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
|
||||
fn poll_flush_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
|
|
|
@ -22,7 +22,8 @@ use crate::task::{Context, Poll};
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn empty() -> Empty {
|
||||
#[must_use]
|
||||
pub const fn empty() -> Empty {
|
||||
Empty { _private: () }
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
//! nickname: readers and writers. So you'll sometimes see 'a reader' instead
|
||||
//! 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`]
|
||||
//! 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
|
||||
//! 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
|
||||
//! making near-constant calls to the operating system. To help with this,
|
||||
|
@ -214,7 +214,7 @@
|
|||
//!
|
||||
//! [functions-list]: #functions-1
|
||||
//!
|
||||
//! ## io::Result
|
||||
//! ## `io::Result`
|
||||
//!
|
||||
//! 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
|
||||
|
|
|
@ -63,7 +63,7 @@ impl<T, U> Chain<T, U> {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn get_ref(&self) -> (&T, &U) {
|
||||
pub const fn get_ref(&self) -> (&T, &U) {
|
||||
(&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) {
|
||||
let this = self.project();
|
||||
if !*this.done_first {
|
||||
this.first.consume(amt)
|
||||
} else {
|
||||
if *this.done_first {
|
||||
this.second.consume(amt)
|
||||
} else {
|
||||
this.first.consume(amt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -392,7 +392,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_read_by_ref() {
|
||||
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 other_buffer = Vec::new();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<T> Take<T> {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn limit(&self) -> u64 {
|
||||
pub const fn limit(&self) -> u64 {
|
||||
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]);
|
||||
|
||||
task::block_on(async move {
|
||||
let mut buffer = [0u8; 5];
|
||||
let mut buffer = [0_u8; 5];
|
||||
|
||||
// read at most five bytes
|
||||
let mut handle = source.take(5);
|
||||
|
|
|
@ -23,7 +23,8 @@ use crate::task::{Context, Poll};
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn repeat(byte: u8) -> Repeat {
|
||||
#[must_use]
|
||||
pub const fn repeat(byte: u8) -> Repeat {
|
||||
Repeat { byte }
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ use crate::task::{Context, Poll};
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub fn sink() -> Sink {
|
||||
#[must_use]
|
||||
pub const fn sink() -> Sink {
|
||||
Sink { _private: () }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::io::{self, Write};
|
||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||
|
@ -30,6 +30,7 @@ use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn stderr() -> Stderr {
|
||||
Stderr(Mutex::new(State::Idle(Some(Inner {
|
||||
stderr: std::io::stderr(),
|
||||
|
@ -150,16 +151,15 @@ impl Write for Stderr {
|
|||
// Check if the operation has completed.
|
||||
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
||||
return Poll::Ready(res);
|
||||
} else {
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
let res = std::io::Write::flush(&mut inner.stderr);
|
||||
inner.last_op = Some(Operation::Flush(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
let res = std::io::Write::flush(&mut inner.stderr);
|
||||
inner.last_op = Some(Operation::Flush(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
// Poll the asynchronous operation the stderr is currently blocked on.
|
||||
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
||||
|
|
|
@ -32,6 +32,7 @@ use crate::utils::Context as _;
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn stdin() -> Stdin {
|
||||
Stdin(Mutex::new(State::Idle(Some(Inner {
|
||||
stdin: std::io::stdin(),
|
||||
|
@ -125,17 +126,16 @@ impl Stdin {
|
|||
// Copy the read data into the buffer and return.
|
||||
buf.push_str(&inner.line);
|
||||
return Poll::Ready(Ok(n));
|
||||
} else {
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
inner.line.clear();
|
||||
let res = inner.stdin.read_line(&mut inner.line);
|
||||
inner.last_op = Some(Operation::ReadLine(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
inner.line.clear();
|
||||
let res = inner.stdin.read_line(&mut inner.line);
|
||||
inner.last_op = Some(Operation::ReadLine(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
// Poll the asynchronous operation the stdin is currently blocked on.
|
||||
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::sync::Mutex;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::io::{self, Write};
|
||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||
|
@ -30,6 +30,7 @@ use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn stdout() -> Stdout {
|
||||
Stdout(Mutex::new(State::Idle(Some(Inner {
|
||||
stdout: std::io::stdout(),
|
||||
|
@ -150,16 +151,15 @@ impl Write for Stdout {
|
|||
// Check if the operation has completed.
|
||||
if let Some(Operation::Flush(res)) = inner.last_op.take() {
|
||||
return Poll::Ready(res);
|
||||
} else {
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
let res = std::io::Write::flush(&mut inner.stdout);
|
||||
inner.last_op = Some(Operation::Flush(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
let mut inner = opt.take().unwrap();
|
||||
|
||||
// Start the operation asynchronously.
|
||||
*state = State::Busy(spawn_blocking(move || {
|
||||
let res = std::io::Write::flush(&mut inner.stdout);
|
||||
inner.last_op = Some(Operation::Flush(res));
|
||||
State::Idle(Some(inner))
|
||||
}));
|
||||
}
|
||||
// Poll the asynchronous operation the stdout is currently blocked on.
|
||||
State::Busy(task) => *state = futures_core::ready!(Pin::new(task).poll(cx)),
|
||||
|
|
|
@ -67,7 +67,7 @@ where
|
|||
let this = self.project();
|
||||
match this.future.poll(cx) {
|
||||
Poll::Pending => {}
|
||||
other => return other,
|
||||
other @ Poll::Ready(..) => return other,
|
||||
}
|
||||
|
||||
if this.timeout.poll(cx).is_ready() {
|
||||
|
|
|
@ -146,6 +146,7 @@ impl TcpListener {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn incoming(&self) -> Incoming<'_> {
|
||||
Incoming {
|
||||
incoming: Box::pin(self.watcher.incoming()),
|
||||
|
|
|
@ -127,6 +127,7 @@ impl UnixListener {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn incoming(&self) -> Incoming<'_> {
|
||||
Incoming {
|
||||
incoming: Box::pin(self.watcher.incoming()),
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::path::Path;
|
|||
///
|
||||
/// [`ancestors`]: struct.Path.html#method.ancestors
|
||||
/// [`Path`]: struct.Path.html
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Ancestors<'a> {
|
||||
pub(crate) next: Option<&'a Path>,
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ impl<'a> Components<'a> {
|
|||
///
|
||||
/// assert_eq!(Path::new("foo/bar.txt"), components.as_path());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn as_path(&self) -> &'a Path {
|
||||
self.inner.as_path().into()
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ impl<'a> Iter<'a> {
|
|||
///
|
||||
/// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn as_path(&self) -> &'a Path {
|
||||
self.inner.as_path()
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ impl Path {
|
|||
/// let os_str = Path::new("foo.txt").as_os_str();
|
||||
/// assert_eq!(os_str, OsStr::new("foo.txt"));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn as_os_str(&self) -> &OsStr {
|
||||
self.inner.as_os_str()
|
||||
}
|
||||
|
@ -111,6 +112,7 @@ impl Path {
|
|||
/// let path = Path::new("foo.txt");
|
||||
/// assert_eq!(path.to_str(), Some("foo.txt"));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn to_str(&self) -> Option<&str> {
|
||||
self.inner.to_str()
|
||||
}
|
||||
|
@ -136,6 +138,7 @@ impl Path {
|
|||
///
|
||||
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
|
||||
/// have returned `"fo<66>.txt"`.
|
||||
#[must_use]
|
||||
pub fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||
self.inner.to_string_lossy()
|
||||
}
|
||||
|
@ -152,6 +155,7 @@ impl Path {
|
|||
/// let path_buf = Path::new("foo.txt").to_path_buf();
|
||||
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn to_path_buf(&self) -> PathBuf {
|
||||
PathBuf::from(self.inner.to_path_buf())
|
||||
}
|
||||
|
@ -174,6 +178,7 @@ impl Path {
|
|||
///
|
||||
/// assert!(!Path::new("foo.txt").is_absolute());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn is_absolute(&self) -> bool {
|
||||
self.inner.is_absolute()
|
||||
}
|
||||
|
@ -191,6 +196,7 @@ impl Path {
|
|||
///
|
||||
/// assert!(Path::new("foo.txt").is_relative());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn is_relative(&self) -> bool {
|
||||
self.inner.is_relative()
|
||||
}
|
||||
|
@ -211,6 +217,7 @@ impl Path {
|
|||
///
|
||||
/// assert!(Path::new("/etc/passwd").has_root());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn has_root(&self) -> bool {
|
||||
self.inner.has_root()
|
||||
}
|
||||
|
@ -234,6 +241,7 @@ impl Path {
|
|||
/// assert_eq!(grand_parent, Path::new("/"));
|
||||
/// assert_eq!(grand_parent.parent(), None);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn parent(&self) -> Option<&Path> {
|
||||
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(), None);
|
||||
/// ```
|
||||
pub fn ancestors(&self) -> Ancestors<'_> {
|
||||
#[must_use]
|
||||
pub const fn ancestors(&self) -> Ancestors<'_> {
|
||||
Ancestors { next: Some(&self) }
|
||||
}
|
||||
|
||||
|
@ -287,6 +296,7 @@ impl Path {
|
|||
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
|
||||
/// assert_eq!(None, Path::new("/").file_name());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn file_name(&self) -> Option<&OsStr> {
|
||||
self.inner.file_name()
|
||||
}
|
||||
|
@ -387,6 +397,7 @@ impl Path {
|
|||
///
|
||||
/// assert_eq!("foo", path.file_stem().unwrap());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn file_stem(&self) -> Option<&OsStr> {
|
||||
self.inner.file_stem()
|
||||
}
|
||||
|
@ -412,6 +423,7 @@ impl Path {
|
|||
///
|
||||
/// assert_eq!("rs", path.extension().unwrap());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn extension(&self) -> Option<&OsStr> {
|
||||
self.inner.extension()
|
||||
}
|
||||
|
@ -510,6 +522,7 @@ impl Path {
|
|||
/// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
|
||||
/// assert_eq!(components.next(), None);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn components(&self) -> Components<'_> {
|
||||
Components {
|
||||
inner: self.inner.components(),
|
||||
|
@ -538,6 +551,7 @@ impl Path {
|
|||
/// assert_eq!(it.next(), Some(OsStr::new("foo.txt")));
|
||||
/// assert_eq!(it.next(), None)
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn iter(&self) -> Iter<'_> {
|
||||
Iter {
|
||||
inner: self.components(),
|
||||
|
@ -558,6 +572,7 @@ impl Path {
|
|||
///
|
||||
/// println!("{}", path.display());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn display(&self) -> Display<'_> {
|
||||
self.inner.display()
|
||||
}
|
||||
|
@ -719,7 +734,7 @@ impl Path {
|
|||
/// # See Also
|
||||
///
|
||||
/// 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
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
|
@ -750,8 +765,8 @@ impl Path {
|
|||
/// # See Also
|
||||
///
|
||||
/// 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
|
||||
/// [fs::Metadata::is_file] if it was Ok.
|
||||
/// check errors, call [`fs::metadata`] and handle its Result. Then call
|
||||
/// [`fs::Metadata::is_file`] if it was Ok.
|
||||
///
|
||||
/// [fs::metadata]: ../fs/fn.metadata.html
|
||||
/// [fs::Metadata::is_file]: ../fs/struct.Metadata.html#method.is_file
|
||||
|
@ -787,8 +802,8 @@ impl Path {
|
|||
/// # See Also
|
||||
///
|
||||
/// 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
|
||||
/// [fs::Metadata::is_dir] if it was Ok.
|
||||
/// check errors, call [`fs::metadata`] and handle its Result. Then call
|
||||
/// [`fs::Metadata::is_dir`] if it was Ok.
|
||||
///
|
||||
/// [fs::metadata]: ../fs/fn.metadata.html
|
||||
/// [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_buf = path.into_path_buf();
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn into_path_buf(self: Box<Path>) -> PathBuf {
|
||||
let rw = Box::into_raw(self) as *mut std::path::Path;
|
||||
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 {
|
||||
fn into(self) -> &'a std::path::Path {
|
||||
std::path::Path::new(&self.inner)
|
||||
impl<'a> From<&'a Path> for &'a std::path::Path {
|
||||
fn from(path: &'a Path) -> &'a std::path::Path {
|
||||
std::path::Path::new(&path.inner)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ impl PathBuf {
|
|||
///
|
||||
/// let path = PathBuf::new();
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn new() -> PathBuf {
|
||||
std::path::PathBuf::new().into()
|
||||
}
|
||||
|
@ -48,6 +49,7 @@ impl PathBuf {
|
|||
/// let p = PathBuf::from("/test");
|
||||
/// assert_eq!(Path::new("/test"), p.as_path());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn as_path(&self) -> &Path {
|
||||
self.inner.as_path().into()
|
||||
}
|
||||
|
@ -182,6 +184,7 @@ impl PathBuf {
|
|||
/// let p = PathBuf::from("/the/head");
|
||||
/// let os_str = p.into_os_string();
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn into_os_string(self) -> OsString {
|
||||
self.inner.into_os_string()
|
||||
}
|
||||
|
@ -190,6 +193,7 @@ impl PathBuf {
|
|||
///
|
||||
/// [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
|
||||
/// [`Path`]: struct.Path.html
|
||||
#[must_use]
|
||||
pub fn into_boxed_path(self) -> Box<Path> {
|
||||
let rw = Box::into_raw(self.inner.into_boxed_path()) as *mut Path;
|
||||
unsafe { Box::from_raw(rw) }
|
||||
|
@ -271,7 +275,7 @@ impl Deref for PathBuf {
|
|||
|
||||
impl Borrow<Path> for PathBuf {
|
||||
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 {
|
||||
fn into(self) -> std::path::PathBuf {
|
||||
self.inner
|
||||
impl From<PathBuf> for std::path::PathBuf {
|
||||
fn from(path_buf: PathBuf) -> std::path::PathBuf {
|
||||
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 {
|
||||
_marker: PhantomData,
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@
|
|||
//! can call `next()` on your stream, until it reaches `None`. Let's go over
|
||||
//! 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
|
||||
//! 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) }
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<S> Cloned<S> {
|
||||
pub(super) fn new(stream: S) -> Self {
|
||||
pub(super) const fn new(stream: S) -> Self {
|
||||
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
|
||||
L: Stream + Sized,
|
||||
R: Stream<Item = L::Item> + Sized,
|
||||
|
|
|
@ -13,7 +13,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<S> Copied<S> {
|
||||
pub(super) fn new(stream: S) -> Self {
|
||||
pub(super) const fn new(stream: S) -> Self {
|
||||
Self { stream }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ where
|
|||
this.source.set(this.orig.clone());
|
||||
this.source.poll_next(cx)
|
||||
}
|
||||
item => Poll::Ready(item),
|
||||
item @ Some(..) => Poll::Ready(item),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<S> Enumerate<S> {
|
||||
pub(super) fn new(stream: S) -> Self {
|
||||
pub(super) const fn new(stream: S) -> Self {
|
||||
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
|
||||
L: Stream + Sized,
|
||||
R: Stream + Sized,
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
predicate,
|
||||
|
|
|
@ -15,7 +15,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ where
|
|||
let this = self.project();
|
||||
let next = futures_core::ready!(this.stream.poll_next(cx));
|
||||
match next {
|
||||
Some(v) => match (this.f)(v) {
|
||||
Some(b) => Poll::Ready(Some(b)),
|
||||
None => {
|
||||
Some(v) => (this.f)(v).map_or_else(
|
||||
|| {
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
}
|
||||
},
|
||||
},
|
||||
|b| Poll::Ready(Some(b)),
|
||||
),
|
||||
None => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,13 @@ where
|
|||
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
|
||||
|
||||
match item {
|
||||
Some(v) => match (&mut self.f)(v) {
|
||||
Some(v) => Poll::Ready(Some(v)),
|
||||
None => {
|
||||
Some(v) => (&mut self.f)(v).map_or_else(
|
||||
|| {
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
}
|
||||
},
|
||||
},
|
||||
|v| Poll::Ready(Some(v)),
|
||||
),
|
||||
None => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
f,
|
||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
f,
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<S> Fuse<S> {
|
||||
pub(super) fn new(stream: S) -> Self {
|
||||
pub(super) const fn new(stream: S) -> Self {
|
||||
Self {
|
||||
stream,
|
||||
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
|
||||
L: 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
|
||||
L: Stream + Sized,
|
||||
R: Stream + Sized,
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
f,
|
||||
|
|
|
@ -17,7 +17,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: Stream, R: Stream> Future for LeFuture<L, R>
|
||||
impl<L, R> Future for LeFuture<L, R>
|
||||
where
|
||||
L: 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
|
||||
L: Stream + Sized,
|
||||
R: Stream + Sized,
|
||||
|
|
|
@ -16,7 +16,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
f,
|
||||
|
|
|
@ -18,7 +18,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
compare,
|
||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
max: None,
|
||||
|
|
|
@ -18,7 +18,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
compare,
|
||||
|
|
|
@ -19,7 +19,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
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
|
||||
L: Stream + Sized,
|
||||
R: Stream + Sized,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
use core::task::{Context, Poll};
|
||||
use core::future::Future;
|
||||
|
||||
use crate::stream::Stream;
|
||||
|
||||
|
@ -28,14 +28,15 @@ where
|
|||
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));
|
||||
match next {
|
||||
Some(v) => match self.n {
|
||||
0 => Poll::Ready(Some(v)),
|
||||
_ => {
|
||||
Some(v) => {
|
||||
if let 0 = self.n {
|
||||
Poll::Ready(Some(v))
|
||||
} else {
|
||||
self.n -= 1;
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
}
|
||||
},
|
||||
}
|
||||
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
|
||||
L: Stream + Sized,
|
||||
R: Stream + Sized,
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
state_f: (initial_state, f),
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
predicate: Some(predicate),
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<S> Take<S> {
|
||||
pub(super) fn new(stream: S, remaining: usize) -> Self {
|
||||
pub(super) const fn new(stream: S, remaining: usize) -> Self {
|
||||
Self {
|
||||
stream,
|
||||
remaining,
|
||||
|
|
|
@ -22,7 +22,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
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 {
|
||||
stream,
|
||||
predicate,
|
||||
|
|
|
@ -17,12 +17,14 @@ pub struct Builder {
|
|||
impl Builder {
|
||||
/// Creates a new builder.
|
||||
#[inline]
|
||||
pub fn new() -> Builder {
|
||||
#[must_use]
|
||||
pub const fn new() -> Builder {
|
||||
Builder { name: None }
|
||||
}
|
||||
|
||||
/// Configures the name of the task.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn name(mut self, name: String) -> Builder {
|
||||
self.name = Some(name);
|
||||
self
|
||||
|
|
|
@ -22,6 +22,7 @@ use crate::task::{Task, TaskLocalsWrapper};
|
|||
/// #
|
||||
/// # })
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn current() -> Task {
|
||||
try_current().expect("`task::current()` called outside the context of a task")
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ impl<T> JoinHandle<T> {
|
|||
/// println!("id = {}", handle.task().id());
|
||||
/// #
|
||||
/// # })
|
||||
pub fn task(&self) -> &Task {
|
||||
#[must_use]
|
||||
pub const fn task(&self) -> &Task {
|
||||
&self.task
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Task {
|
|||
|
||||
/// Gets the task's unique identifier.
|
||||
#[inline]
|
||||
pub fn id(&self) -> TaskId {
|
||||
#[must_use] pub const fn id(&self) -> TaskId {
|
||||
self.id
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ impl Task {
|
|||
/// The name is configured by [`Builder::name`] before spawning.
|
||||
///
|
||||
/// [`Builder::name`]: struct.Builder.html#method.name
|
||||
#[must_use]
|
||||
pub fn name(&self) -> Option<&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);
|
||||
|
||||
// Call the closure with the value passed as an argument.
|
||||
f(&*(value as *const T))
|
||||
f(&*value.cast::<T>())
|
||||
})
|
||||
.ok_or(AccessError { _private: () })
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ pub(crate) struct LocalsMap {
|
|||
|
||||
impl LocalsMap {
|
||||
/// Creates an empty map of task-locals.
|
||||
pub fn new() -> LocalsMap {
|
||||
pub const fn new() -> LocalsMap {
|
||||
LocalsMap {
|
||||
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
|
||||
/// demand.
|
||||
#[inline]
|
||||
pub(crate) fn new(task: Task) -> Self {
|
||||
pub(crate) const fn new(task: Task) -> Self {
|
||||
Self {
|
||||
task,
|
||||
locals: LocalsMap::new(),
|
||||
|
@ -33,17 +33,17 @@ impl TaskLocalsWrapper {
|
|||
|
||||
/// Gets the task's unique identifier.
|
||||
#[inline]
|
||||
pub fn id(&self) -> TaskId {
|
||||
pub const fn id(&self) -> TaskId {
|
||||
self.task.id()
|
||||
}
|
||||
|
||||
/// Returns a reference to the inner `Task`.
|
||||
pub(crate) fn task(&self) -> &Task {
|
||||
pub(crate) const fn task(&self) -> &Task {
|
||||
&self.task
|
||||
}
|
||||
|
||||
/// Returns the map holding task-local values.
|
||||
pub(crate) fn locals(&self) -> &LocalsMap {
|
||||
pub(crate) const fn locals(&self) -> &LocalsMap {
|
||||
&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
|
||||
// for other futures to progress.
|
||||
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;
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
} else {
|
||||
Poll::Ready(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@ fn smoke() {
|
|||
let lock = RwLock::new(());
|
||||
drop(lock.read().await);
|
||||
drop(lock.write().await);
|
||||
drop((lock.read().await, lock.read().await));
|
||||
drop(lock.read().await);
|
||||
drop(lock.read().await);
|
||||
drop(lock.write().await);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use async_std::io;
|
||||
use async_std::os::unix::net::{UnixDatagram, UnixListener, UnixStream};
|
||||
use async_std::path::Path;
|
||||
use async_std::prelude::*;
|
||||
use async_std::task;
|
||||
|
||||
|
@ -81,7 +82,7 @@ fn socket_ping_pong() {
|
|||
});
|
||||
|
||||
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();
|
||||
|
@ -102,10 +103,10 @@ async fn ping_pong_server(listener: UnixListener, iterations: u32) -> std::io::R
|
|||
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];
|
||||
for _ix in 0..iterations {
|
||||
let mut socket = UnixStream::connect(&socket).await?;
|
||||
let mut socket = UnixStream::connect(socket).await?;
|
||||
socket.write_all(&PING).await?;
|
||||
let n = async_std::io::timeout(TEST_TIMEOUT, socket.read(&mut buf[..])).await?;
|
||||
assert_eq!(&buf[..n], PONG);
|
||||
|
|
Loading…
Reference in a new issue