|
3 | 3 | #![deny(unsafe_op_in_unsafe_fn)] |
4 | 4 | #![unstable(feature = "wasi_ext", issue = "none")] |
5 | 5 |
|
| 6 | +use crate::ffi::OsStr; |
6 | 7 | use crate::fs::{self, File, Metadata, OpenOptions}; |
7 | 8 | use crate::io::{self, IoSlice, IoSliceMut}; |
8 | 9 | use crate::path::{Path, PathBuf}; |
9 | | -use crate::sys::fs::osstr2str; |
10 | 10 | use crate::sys_common::{AsInner, AsInnerMut, FromInner}; |
| 11 | +// Used for `File::read` on intra-doc links |
| 12 | +#[allow(unused_imports)] |
| 13 | +use io::{Read, Write}; |
11 | 14 |
|
12 | 15 | /// WASI-specific extensions to [`File`]. |
13 | 16 | pub trait FileExt { |
@@ -54,11 +57,11 @@ pub trait FileExt { |
54 | 57 | /// # Errors |
55 | 58 | /// |
56 | 59 | /// If this function encounters an error of the kind |
57 | | - /// [`ErrorKind::Interrupted`] then the error is ignored and the operation |
| 60 | + /// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation |
58 | 61 | /// will continue. |
59 | 62 | /// |
60 | 63 | /// If this function encounters an "end of file" before completely filling |
61 | | - /// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`]. |
| 64 | + /// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`]. |
62 | 65 | /// The contents of `buf` are unspecified in this case. |
63 | 66 | /// |
64 | 67 | /// If any other read error is encountered then this function immediately |
@@ -131,16 +134,16 @@ pub trait FileExt { |
131 | 134 | /// The current file cursor is not affected by this function. |
132 | 135 | /// |
133 | 136 | /// This method will continuously call [`write_at`] until there is no more data |
134 | | - /// to be written or an error of non-[`ErrorKind::Interrupted`] kind is |
| 137 | + /// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is |
135 | 138 | /// returned. This method will not return until the entire buffer has been |
136 | 139 | /// successfully written or such an error occurs. The first error that is |
137 | | - /// not of [`ErrorKind::Interrupted`] kind generated from this method will be |
| 140 | + /// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be |
138 | 141 | /// returned. |
139 | 142 | /// |
140 | 143 | /// # Errors |
141 | 144 | /// |
142 | 145 | /// This function will return the first error of |
143 | | - /// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns. |
| 146 | + /// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns. |
144 | 147 | /// |
145 | 148 | /// [`write_at`]: FileExt::write_at |
146 | 149 | #[stable(feature = "rw_exact_all_at", since = "1.33.0")] |
@@ -426,7 +429,7 @@ impl MetadataExt for fs::Metadata { |
426 | 429 | } |
427 | 430 | } |
428 | 431 |
|
429 | | -/// WASI-specific extensions for [`FileType`]. |
| 432 | +/// WASI-specific extensions for [`fs::FileType`]. |
430 | 433 | /// |
431 | 434 | /// Adds support for special WASI file types such as block/character devices, |
432 | 435 | /// pipes, and sockets. |
@@ -517,8 +520,12 @@ pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>( |
517 | 520 |
|
518 | 521 | /// Create a symbolic link. |
519 | 522 | /// |
520 | | -/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and |
521 | | -/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir). |
| 523 | +/// This is a convenience API similar to `std::os::unix::fs::symlink` and |
| 524 | +/// `std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`. |
522 | 525 | pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> { |
523 | 526 | crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref()) |
524 | 527 | } |
| 528 | + |
| 529 | +fn osstr2str(f: &OsStr) -> io::Result<&str> { |
| 530 | + f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) |
| 531 | +} |
0 commit comments