Skip to content

Commit

Permalink
support hermit (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mueller678 authored Oct 24, 2024
1 parent b08a655 commit bf089c4
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ use crate::host::HostInternal;

use crate::net::IpAddr;
#[cfg(feature = "std")]
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[cfg(any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
))]
use crate::net::{SocketAddr, ToSocketAddrs};
use crate::parser::{to_u32, Context, Parser, SchemeType, USERINFO};
use alloc::borrow::ToOwned;
Expand All @@ -181,7 +187,13 @@ use core::ops::{Range, RangeFrom, RangeTo};
use core::{cmp, fmt, hash, mem};
use percent_encoding::utf8_percent_encode;
#[cfg(feature = "std")]
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[cfg(any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
))]
use std::io;
#[cfg(feature = "std")]
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1308,7 +1320,13 @@ impl Url {
/// }
/// ```
#[cfg(feature = "std")]
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
#[cfg(any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
))]
pub fn socket_addrs(
&self,
default_port_number: impl Fn() -> Option<u16>,
Expand Down Expand Up @@ -2566,7 +2584,13 @@ impl Url {
/// This method is only available if the `std` Cargo feature is enabled.
#[cfg(all(
feature = "std",
any(unix, windows, target_os = "redox", target_os = "wasi")
any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
)
))]
#[allow(clippy::result_unit_err)]
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
Expand Down Expand Up @@ -2608,7 +2632,13 @@ impl Url {
/// This method is only available if the `std` Cargo feature is enabled.
#[cfg(all(
feature = "std",
any(unix, windows, target_os = "redox", target_os = "wasi")
any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
)
))]
#[allow(clippy::result_unit_err)]
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
Expand Down Expand Up @@ -2730,7 +2760,13 @@ impl Url {
#[inline]
#[cfg(all(
feature = "std",
any(unix, windows, target_os = "redox", target_os = "wasi")
any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
)
))]
#[allow(clippy::result_unit_err)]
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
Expand Down Expand Up @@ -2935,13 +2971,18 @@ impl<'de> serde::Deserialize<'de> for Url {
}
}

#[cfg(all(feature = "std", any(unix, target_os = "redox", target_os = "wasi")))]
#[cfg(all(
feature = "std",
any(unix, target_os = "redox", target_os = "wasi", target_os = "hermit")
))]
fn path_to_file_url_segments(
path: &Path,
serialization: &mut String,
) -> Result<(u32, HostInternal), ()> {
use parser::SPECIAL_PATH_SEGMENT;
use percent_encoding::percent_encode;
#[cfg(target_os = "hermit")]
use std::os::hermit::ffi::OsStrExt;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
#[cfg(target_os = "wasi")]
Expand Down Expand Up @@ -3042,14 +3083,19 @@ fn path_to_file_url_segments_windows(
Ok((host_end, host_internal))
}

#[cfg(all(feature = "std", any(unix, target_os = "redox", target_os = "wasi")))]
#[cfg(all(
feature = "std",
any(unix, target_os = "redox", target_os = "wasi", target_os = "hermit")
))]
fn file_url_segments_to_pathbuf(
host: Option<&str>,
segments: str::Split<'_, char>,
) -> Result<PathBuf, ()> {
use alloc::vec::Vec;
use percent_encoding::percent_decode;
use std::ffi::OsStr;
#[cfg(target_os = "hermit")]
use std::os::hermit::ffi::OsStrExt;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::prelude::OsStrExt;
#[cfg(target_os = "wasi")]
Expand Down

0 comments on commit bf089c4

Please sign in to comment.