Skip to content

Commit bf089c4

Browse files
authored
support hermit (#985)
1 parent b08a655 commit bf089c4

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

url/src/lib.rs

+54-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ use crate::host::HostInternal;
168168

169169
use crate::net::IpAddr;
170170
#[cfg(feature = "std")]
171-
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
171+
#[cfg(any(
172+
unix,
173+
windows,
174+
target_os = "redox",
175+
target_os = "wasi",
176+
target_os = "hermit"
177+
))]
172178
use crate::net::{SocketAddr, ToSocketAddrs};
173179
use crate::parser::{to_u32, Context, Parser, SchemeType, USERINFO};
174180
use alloc::borrow::ToOwned;
@@ -181,7 +187,13 @@ use core::ops::{Range, RangeFrom, RangeTo};
181187
use core::{cmp, fmt, hash, mem};
182188
use percent_encoding::utf8_percent_encode;
183189
#[cfg(feature = "std")]
184-
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
190+
#[cfg(any(
191+
unix,
192+
windows,
193+
target_os = "redox",
194+
target_os = "wasi",
195+
target_os = "hermit"
196+
))]
185197
use std::io;
186198
#[cfg(feature = "std")]
187199
use std::path::{Path, PathBuf};
@@ -1308,7 +1320,13 @@ impl Url {
13081320
/// }
13091321
/// ```
13101322
#[cfg(feature = "std")]
1311-
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
1323+
#[cfg(any(
1324+
unix,
1325+
windows,
1326+
target_os = "redox",
1327+
target_os = "wasi",
1328+
target_os = "hermit"
1329+
))]
13121330
pub fn socket_addrs(
13131331
&self,
13141332
default_port_number: impl Fn() -> Option<u16>,
@@ -2566,7 +2584,13 @@ impl Url {
25662584
/// This method is only available if the `std` Cargo feature is enabled.
25672585
#[cfg(all(
25682586
feature = "std",
2569-
any(unix, windows, target_os = "redox", target_os = "wasi")
2587+
any(
2588+
unix,
2589+
windows,
2590+
target_os = "redox",
2591+
target_os = "wasi",
2592+
target_os = "hermit"
2593+
)
25702594
))]
25712595
#[allow(clippy::result_unit_err)]
25722596
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
@@ -2608,7 +2632,13 @@ impl Url {
26082632
/// This method is only available if the `std` Cargo feature is enabled.
26092633
#[cfg(all(
26102634
feature = "std",
2611-
any(unix, windows, target_os = "redox", target_os = "wasi")
2635+
any(
2636+
unix,
2637+
windows,
2638+
target_os = "redox",
2639+
target_os = "wasi",
2640+
target_os = "hermit"
2641+
)
26122642
))]
26132643
#[allow(clippy::result_unit_err)]
26142644
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
@@ -2730,7 +2760,13 @@ impl Url {
27302760
#[inline]
27312761
#[cfg(all(
27322762
feature = "std",
2733-
any(unix, windows, target_os = "redox", target_os = "wasi")
2763+
any(
2764+
unix,
2765+
windows,
2766+
target_os = "redox",
2767+
target_os = "wasi",
2768+
target_os = "hermit"
2769+
)
27342770
))]
27352771
#[allow(clippy::result_unit_err)]
27362772
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
@@ -2935,13 +2971,18 @@ impl<'de> serde::Deserialize<'de> for Url {
29352971
}
29362972
}
29372973

2938-
#[cfg(all(feature = "std", any(unix, target_os = "redox", target_os = "wasi")))]
2974+
#[cfg(all(
2975+
feature = "std",
2976+
any(unix, target_os = "redox", target_os = "wasi", target_os = "hermit")
2977+
))]
29392978
fn path_to_file_url_segments(
29402979
path: &Path,
29412980
serialization: &mut String,
29422981
) -> Result<(u32, HostInternal), ()> {
29432982
use parser::SPECIAL_PATH_SEGMENT;
29442983
use percent_encoding::percent_encode;
2984+
#[cfg(target_os = "hermit")]
2985+
use std::os::hermit::ffi::OsStrExt;
29452986
#[cfg(any(unix, target_os = "redox"))]
29462987
use std::os::unix::prelude::OsStrExt;
29472988
#[cfg(target_os = "wasi")]
@@ -3042,14 +3083,19 @@ fn path_to_file_url_segments_windows(
30423083
Ok((host_end, host_internal))
30433084
}
30443085

3045-
#[cfg(all(feature = "std", any(unix, target_os = "redox", target_os = "wasi")))]
3086+
#[cfg(all(
3087+
feature = "std",
3088+
any(unix, target_os = "redox", target_os = "wasi", target_os = "hermit")
3089+
))]
30463090
fn file_url_segments_to_pathbuf(
30473091
host: Option<&str>,
30483092
segments: str::Split<'_, char>,
30493093
) -> Result<PathBuf, ()> {
30503094
use alloc::vec::Vec;
30513095
use percent_encoding::percent_decode;
30523096
use std::ffi::OsStr;
3097+
#[cfg(target_os = "hermit")]
3098+
use std::os::hermit::ffi::OsStrExt;
30533099
#[cfg(any(unix, target_os = "redox"))]
30543100
use std::os::unix::prelude::OsStrExt;
30553101
#[cfg(target_os = "wasi")]

0 commit comments

Comments
 (0)