Skip to content

Commit d34c8b3

Browse files
authored
Merge pull request #738 from HKalbasi/master
Add file related methods for wasi
2 parents f6df441 + 53b2518 commit d34c8b3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

url/src/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ impl Url {
23212321
/// # run().unwrap();
23222322
/// # }
23232323
/// ```
2324-
#[cfg(any(unix, windows, target_os = "redox"))]
2324+
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
23252325
#[allow(clippy::result_unit_err)]
23262326
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
23272327
let mut serialization = "file://".to_owned();
@@ -2358,7 +2358,7 @@ impl Url {
23582358
///
23592359
/// Note that `std::path` does not consider trailing slashes significant
23602360
/// and usually does not include them (e.g. in `Path::parent()`).
2361-
#[cfg(any(unix, windows, target_os = "redox"))]
2361+
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
23622362
#[allow(clippy::result_unit_err)]
23632363
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
23642364
let mut url = Url::from_file_path(path)?;
@@ -2475,7 +2475,7 @@ impl Url {
24752475
/// (That is, if the percent-decoded path contains a NUL byte or,
24762476
/// for a Windows path, is not UTF-8.)
24772477
#[inline]
2478-
#[cfg(any(unix, windows, target_os = "redox"))]
2478+
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
24792479
#[allow(clippy::result_unit_err)]
24802480
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
24812481
if let Some(segments) = self.path_segments() {
@@ -2679,12 +2679,15 @@ impl<'de> serde::Deserialize<'de> for Url {
26792679
}
26802680
}
26812681

2682-
#[cfg(any(unix, target_os = "redox"))]
2682+
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
26832683
fn path_to_file_url_segments(
26842684
path: &Path,
26852685
serialization: &mut String,
26862686
) -> Result<(u32, HostInternal), ()> {
2687+
#[cfg(any(unix, target_os = "redox"))]
26872688
use std::os::unix::prelude::OsStrExt;
2689+
#[cfg(target_os = "wasi")]
2690+
use std::os::wasi::prelude::OsStrExt;
26882691
if !path.is_absolute() {
26892692
return Err(());
26902693
}
@@ -2774,13 +2777,16 @@ fn path_to_file_url_segments_windows(
27742777
Ok((host_end, host_internal))
27752778
}
27762779

2777-
#[cfg(any(unix, target_os = "redox"))]
2780+
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
27782781
fn file_url_segments_to_pathbuf(
27792782
host: Option<&str>,
27802783
segments: str::Split<'_, char>,
27812784
) -> Result<PathBuf, ()> {
27822785
use std::ffi::OsStr;
2786+
#[cfg(any(unix, target_os = "redox"))]
27832787
use std::os::unix::prelude::OsStrExt;
2788+
#[cfg(target_os = "wasi")]
2789+
use std::os::wasi::prelude::OsStrExt;
27842790

27852791
if host.is_some() {
27862792
return Err(());

0 commit comments

Comments
 (0)