Skip to content

Commit

Permalink
chore: use argument position impl trait (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
faern authored and carllerche committed Oct 26, 2019
1 parent 987ba73 commit 474befd
Show file tree
Hide file tree
Showing 24 changed files with 27 additions and 59 deletions.
2 changes: 1 addition & 1 deletion tokio/src/fs/create_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::create_dir`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.create_dir.html
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
pub async fn create_dir(path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::create_dir(path)).await
}
2 changes: 1 addition & 1 deletion tokio/src/fs/create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::create_dir_all`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.create_dir_all.html
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
pub async fn create_dir_all(path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::create_dir_all(path)).await
}
10 changes: 2 additions & 8 deletions tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ impl File {
/// # Ok(())
/// # }
/// ```
pub async fn open<P>(path: P) -> io::Result<File>
where
P: AsRef<Path>,
{
pub async fn open(path: impl AsRef<Path>) -> io::Result<File> {
let path = path.as_ref().to_owned();
let std = asyncify(|| sys::File::open(path)).await?;

Expand Down Expand Up @@ -153,10 +150,7 @@ impl File {
/// # Ok(())
/// # }
/// ```
pub async fn create<P>(path: P) -> io::Result<File>
where
P: AsRef<Path>,
{
pub async fn create(path: impl AsRef<Path>) -> io::Result<File> {
let path = path.as_ref().to_owned();
let std_file = asyncify(move || sys::File::create(path)).await?;
Ok(File::from_std(std_file))
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/hard_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::hard_link`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.hard_link.html
pub async fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
pub async fn hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
5 changes: 1 addition & 4 deletions tokio/src/fs/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use std::io;
use std::path::Path;

/// Queries the file system metadata for a path.
pub async fn metadata<P>(path: P) -> io::Result<Metadata>
where
P: AsRef<Path>,
{
pub async fn metadata(path: impl AsRef<Path>) -> io::Result<Metadata> {
let path = path.as_ref().to_owned();
asyncify(|| std::fs::metadata(path)).await
}
5 changes: 1 addition & 4 deletions tokio/src/fs/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl OpenOptions {
/// Tokio runtime or if the underlying [`open`] call results in an error.
///
/// [`open`]: https://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open
pub async fn open<P>(&self, path: P) -> io::Result<File>
where
P: AsRef<Path>,
{
pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
let path = path.as_ref().to_owned();
let opts = self.0.clone();

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/os/unix/symlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::Path;
/// This is an async version of [`std::os::unix::fs::symlink`][std]
///
/// [std]: https://doc.rust-lang.org/std/os/unix/fs/fn.symlink.html
pub async fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
pub async fn symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/os/windows/symlink_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
/// This is an async version of [`std::os::windows::fs::symlink_dir`][std]
///
/// [std]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html
pub async fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
pub async fn symlink_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/os/windows/symlink_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
/// This is an async version of [`std::os::windows::fs::symlink_file`][std]
///
/// [std]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_file.html
pub async fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
pub async fn symlink_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
5 changes: 1 addition & 4 deletions tokio/src/fs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use std::{io, path::Path};
/// # Ok(())
/// # }
/// ```
pub async fn read<P>(path: P) -> io::Result<Vec<u8>>
where
P: AsRef<Path>,
{
pub async fn read(path: impl AsRef<Path>) -> io::Result<Vec<u8>> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::read(path)).await
}
5 changes: 1 addition & 4 deletions tokio/src/fs/read_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use std::task::Poll;
/// Returns a stream over the entries within a directory.
///
/// This is an async version of [`std::fs::read_dir`](std::fs::read_dir)
pub async fn read_dir<P>(path: P) -> io::Result<ReadDir>
where
P: AsRef<Path>,
{
pub async fn read_dir(path: impl AsRef<Path>) -> io::Result<ReadDir> {
let path = path.as_ref().to_owned();
let std = asyncify(|| std::fs::read_dir(path)).await?;

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/read_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
/// This is an async version of [`std::fs::read_link`][std]
///
/// [std]: std::fs::read_link
pub async fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
pub async fn read_link(path: impl AsRef<Path>) -> io::Result<PathBuf> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::read_link(path)).await
}
5 changes: 1 addition & 4 deletions tokio/src/fs/read_to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use std::{io, path::Path};
/// # Ok(())
/// # }
/// ```
pub async fn read_to_string<P>(path: P) -> io::Result<String>
where
P: AsRef<Path>,
{
pub async fn read_to_string(path: impl AsRef<Path>) -> io::Result<String> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::read_to_string(path)).await
}
2 changes: 1 addition & 1 deletion tokio/src/fs/remove_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::Path;
/// Removes an existing, empty directory.
///
/// This is an async version of [`std::fs::remove_dir`](std::fs::remove_dir)
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
pub async fn remove_dir(path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::remove_dir(path)).await
}
2 changes: 1 addition & 1 deletion tokio/src/fs/remove_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::remove_dir_all`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.remove_dir_all.html
pub async fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
pub async fn remove_dir_all(path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::remove_dir_all(path)).await
}
2 changes: 1 addition & 1 deletion tokio/src/fs/remove_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::remove_file`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.remove_file.html
pub async fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
pub async fn remove_file(path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(move || std::fs::remove_file(path)).await
}
2 changes: 1 addition & 1 deletion tokio/src/fs/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::Path;
/// This will not work if the new name is on a different mount point.
///
/// This is an async version of [`std::fs::rename`](std::fs::rename)
pub async fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
pub async fn rename(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
let from = from.as_ref().to_owned();
let to = to.as_ref().to_owned();

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/set_permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::set_permissions`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.set_permissions.html
pub async fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
pub async fn set_permissions(path: impl AsRef<Path>, perm: Permissions) -> io::Result<()> {
let path = path.as_ref().to_owned();
asyncify(|| std::fs::set_permissions(path, perm)).await
}
5 changes: 1 addition & 4 deletions tokio/src/fs/symlink_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use std::path::Path;
/// This is an async version of [`std::fs::symlink_metadata`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.symlink_metadata.html
pub async fn symlink_metadata<P>(path: P) -> io::Result<Metadata>
where
P: AsRef<Path>,
{
pub async fn symlink_metadata(path: impl AsRef<Path>) -> io::Result<Metadata> {
let path = path.as_ref().to_owned();
asyncify(|| std::fs::symlink_metadata(path)).await
}
5 changes: 1 addition & 4 deletions tokio/src/fs/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use std::{io, path::Path};
/// # Ok(())
/// # }
/// ```
pub async fn write<P, C: AsRef<[u8]> + Unpin>(path: P, contents: C) -> io::Result<()>
where
P: AsRef<Path>,
{
pub async fn write<C: AsRef<[u8]> + Unpin>(path: impl AsRef<Path>, contents: C) -> io::Result<()> {
let path = path.as_ref().to_owned();
let contents = contents.as_ref().to_owned();

Expand Down
5 changes: 1 addition & 4 deletions tokio/src/runtime/current_thread/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ impl Runtime {
///
/// The caller is responsible for ensuring that other spawned futures
/// complete execution by calling `block_on` or `run`.
pub fn block_on<F>(&mut self, f: F) -> F::Output
where
F: Future,
{
pub fn block_on<F: Future>(&mut self, f: F) -> F::Output {
self.enter(|executor| {
// Run the provided future
executor.block_on(f)
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/threadpool/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Builder {
/// .build();
/// # }
/// ```
pub fn name<S: Into<String>>(&mut self, val: S) -> &mut Self {
pub fn name(&mut self, val: impl Into<String>) -> &mut Self {
self.thread_pool_builder.name(val);
self
}
Expand Down
8 changes: 3 additions & 5 deletions tokio/src/runtime/threadpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ impl Runtime {
/// This function panics if the spawn fails. Failure occurs if the executor
/// is currently at capacity and is unable to spawn a new future.
pub fn spawn<F>(&self, future: F) -> &Self
where F: Future<Output = ()> + Send + 'static,
where
F: Future<Output = ()> + Send + 'static,
{
self.inner().pool.spawn(future);
self
Expand All @@ -129,10 +130,7 @@ impl Runtime {
///
/// This function panics if the executor is at capacity, if the provided
/// future panics, or if called within an asynchronous execution context.
pub fn block_on<F>(&self, future: F) -> F::Output
where
F: Future,
{
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
let _reactor = driver::set_default(&self.inner().reactor_handles[0]);
let _timer = timer::set_default(&self.inner().timer_handles[0]);

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/timer/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Clock {
}

/// Return a new `Clock` instance that uses `now` as the source of time.
pub fn new_with_now<T: Now>(now: T) -> Clock {
pub fn new_with_now(now: impl Now) -> Clock {
Clock {
now: Some(Arc::new(now)),
}
Expand Down

0 comments on commit 474befd

Please sign in to comment.