Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tracking] path #183

stjepang opened this issue Sep 11, 2019 · 4 comments · Fixed by #320


Copy link

commented Sep 11, 2019

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) = {
    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()?);



  • 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::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
@yoshuawuyts yoshuawuyts added this to the std parity milestone Sep 19, 2019
@yoshuawuyts yoshuawuyts changed the title Async version of Path [tracking] path Sep 19, 2019
bors bot added a commit that referenced this issue Oct 6, 2019
Merge #282
282: init path submodule as unstable r=yoshuawuyts a=yoshuawuyts

Ref #183.

Similar to #257 this adds the `path` submodule as unstable. Filling in all re-exports from std for module completion. From there the we can build out `Path` and `PathBuf` accordingly. Thanks!

Co-authored-by: Yoshua Wuyts <>

This comment has been minimized.

Copy link

commented Oct 6, 2019

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

This comment has been minimized.

Copy link

commented Oct 6, 2019

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


This comment has been minimized.

Copy link

commented Oct 11, 2019

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


This comment has been minimized.

Copy link

commented Oct 11, 2019

@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!

@Wassasin Wassasin referenced this issue Oct 13, 2019
39 of 39 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.