Async-std: [tracking] path

Created on 11 Sep 2019  路  4Comments  路  Source: async-rs/async-std

The std::path::Path struct has some blocking methods like read_dir which should be asynchronous in our library.

That means we'll need to have our own async_std::path::Path that is convertible to/from std::path::Path. Moreover, since PathBuf derefs into Path, we'll also need an async version of PathBuf.

Right now, we're using std::path::Path throughout async-std, which might cause users to accidentally call blocking functions without realizing. For example:

let mut dir = fs::read_dir(".").await?;

while let Some(entry) = dir.next().await {
    let path = entry?.path();

    // Ooops, the `path.canonicalize()` call here is blocking!
    //
    // We should use an async version of `PathBuf` here and
    // do `path.canonicalize().await` instead.
    println!("{:?}", path.canonicalize()?);
}

Tasks

PathBuf

  • [ ] path::PathBuf::as_path
  • [ ] path::PathBuf::capacity
  • [ ] path::PathBuf::clear
  • [ ] path::PathBuf::into_boxed_path
  • [ ] path::PathBuf::into_os_string
  • [ ] path::PathBuf::new
  • [ ] path::PathBuf::pop
  • [ ] path::PathBuf::push
  • [ ] path::PathBuf::reserve
  • [ ] path::PathBuf::reserve_exact
  • [ ] path::PathBuf::set_extension
  • [ ] path::PathBuf::set_file_name
  • [ ] path::PathBuf::shrink_to
  • [ ] path::PathBuf::shrink_to_fit
  • [ ] path::PathBuf::with_capacity
  • [ ] impl<P: AsRef<Path>> FromStream<P> for PathBuf

Path

  • [ ] path::Path::ancestors
  • [ ] path::Path::as_os_str
  • [ ] path::Path::canonicalize
  • [ ] path::Path::components
  • [ ] path::Path::display
  • [ ] path::Path::ends_with
  • [ ] path::Path::exists
  • [ ] path::Path::extension
  • [ ] path::Path::file_name
  • [ ] path::Path::file_stem
  • [ ] path::Path::has_root
  • [ ] path::Path::into_path_buf
  • [ ] path::Path::is_absolute
  • [ ] path::Path::is_dir
  • [ ] path::Path::is_file
  • [ ] path::Path::is_relative
  • [ ] path::Path::iter
  • [ ] path::Path::join
  • [ ] path::Path::metadata
  • [ ] path::Path::new
  • [ ] path::Path::parent
  • [ ] path::Path::read_dir
  • [ ] path::Path::read_link
  • [ ] path::Path::starts_with
  • [ ] path::Path::strip_prefix
  • [ ] path::Path::symlink_metadata
  • [ ] path::Path::to_path_buf
  • [ ] path::Path::to_str
  • [ ] path::Path::to_string_lossy
  • [ ] path::Path::with_extension
  • [ ] path::Path::with_file_name
api design enhancement

Most helpful comment

I'm interested in implementing this feature. It's basically invoking blocking::spawn on filesystem operations, right?

All 4 comments

Though it's not super related to the issue description, I highly suggest that as part of this you add the FromStream impl for PathBuf.

Here's the FromIterator impl:

impl<P: AsRef<Path>> FromIterator<P> for PathBuf

@sunjay that's an excellent suggestion; thanks so much!

I'm interested in implementing this feature. It's basically invoking blocking::spawn on filesystem operations, right?

@pandaman64 yes, that's exactly it! Additionally some methods such as Path::canonicalize can be forwarded to existing implementations such as fs::canonicalize. All in all this should be relatively straight forward!

Was this page helpful?
0 / 5 - 0 ratings