Add file related methods for wasi
@@ -2321,7 +2321,7 @@ impl Url {
/// # run().unwrap();
/// # }
/// ```
- #[cfg(any(unix, windows, target_os = "redox"))]
+ #[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[allow(clippy::result_unit_err)]
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
let mut serialization = "file://".to_owned();
@@ -2358,7 +2358,7 @@ impl Url {
///
/// Note that `std::path` does not consider trailing slashes significant
/// and usually does not include them (e.g. in `Path::parent()`).
- #[cfg(any(unix, windows, target_os = "redox"))]
+ #[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[allow(clippy::result_unit_err)]
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
let mut url = Url::from_file_path(path)?;
@@ -2475,7 +2475,7 @@ impl Url {
/// (That is, if the percent-decoded path contains a NUL byte or,
/// for a Windows path, is not UTF-8.)
#[inline]
- #[cfg(any(unix, windows, target_os = "redox"))]
+ #[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[allow(clippy::result_unit_err)]
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
if let Some(segments) = self.path_segments() {
@@ -2679,12 +2679,15 @@ impl<'de> serde::Deserialize<'de> for Url {
}
}
-#[cfg(any(unix, target_os = "redox"))]
+#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
fn path_to_file_url_segments(
path: &Path,
serialization: &mut String,
) -> Result<(u32, HostInternal), ()> {
+ #[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
+ #[cfg(target_os = "wasi")]
+ use std::os::wasi::prelude::OsStrExt;
if !path.is_absolute() {
return Err(());
}
@@ -2774,13 +2777,16 @@ fn path_to_file_url_segments_windows(
Ok((host_end, host_internal))
}
-#[cfg(any(unix, target_os = "redox"))]
+#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
fn file_url_segments_to_pathbuf(
host: Option<&str>,
segments: str::Split<'_, char>,
) -> Result<PathBuf, ()> {
use std::ffi::OsStr;
+ #[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
+ #[cfg(target_os = "wasi")]
+ use std::os::wasi::prelude::OsStrExt;
if host.is_some() {
return Err(());
