Skip to content

Commit fc0778f

Browse files
committed
Merge remote-tracking branch 'mspiegel/no_std' into no_std
2 parents 00efb8f + 619de8e commit fc0778f

File tree

6 files changed

+39
-45
lines changed

6 files changed

+39
-45
lines changed

url/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/url"
1010
repository = "https://github.com/servo/rust-url"
1111
readme = "../README.md"
1212
keywords = ["url", "parser"]
13-
categories = ["parser-implementations", "web-programming", "encoding"]
13+
categories = ["parser-implementations", "web-programming", "encoding", "no_std"]
1414
license = "MIT OR Apache-2.0"
1515
include = ["src/**/*", "LICENSE-*", "README.md", "tests/**"]
1616
edition = "2018"
@@ -34,7 +34,8 @@ no-std-net = { version = "0.6.0", default-features = false, optional = true }
3434
[features]
3535
default = ["std"]
3636
std = ["idna/std", "percent-encoding/std", "form_urlencoded/std", "alloc"]
37-
alloc = []
37+
alloc = ["form_urlencoded/alloc", "idna/alloc", "percent-encoding/alloc"]
38+
3839
# Enable to use the #[debugger_visualizer] attribute. This feature requires Rust >= 1.71.
3940
debugger_visualizer = []
4041
# Expose internal offsets of the URL.

url/src/host.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9+
use alloc::borrow::ToOwned;
10+
use alloc::string::String;
11+
use alloc::string::ToString;
12+
use alloc::vec::Vec;
13+
use core::cmp;
14+
use core::fmt::{self, Formatter};
915
use crate::net::{Ipv4Addr, Ipv6Addr};
10-
use alloc::{
11-
borrow::ToOwned,
12-
string::{String, ToString},
13-
vec::Vec,
14-
};
15-
use core::{
16-
cmp,
17-
fmt::{self, Formatter},
18-
};
1916

2017
use percent_encoding::{percent_decode, utf8_percent_encode, CONTROLS};
2118
#[cfg(feature = "serde")]

url/src/lib.rs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ assert!(data_url.fragment() == Some(""));
7373
# run().unwrap();
7474
```
7575
76+
## Default Features
77+
78+
Versions `< 3` of the crate have no default features. Versions `>= 3` have the default feature 'std'.
79+
If you are upgrading across this boundary and you have specified `default-features = false`, then
80+
you will need to add the 'std' feature or the 'alloc' feature to your dependency.
81+
The 'std' feature has the same behavior as the previous versions. The 'alloc' feature
82+
provides no_std support.
83+
7684
## Serde
7785
7886
Enable the `serde` feature to include `Deserialize` and `Serialize` implementations for `url::Url`.
@@ -140,18 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
140148
feature = "debugger_visualizer",
141149
debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
142150
)]
143-
#![cfg_attr(
144-
all(
145-
not(feature = "std"),
146-
not(feature = "no_std_net"),
147-
feature = "unstable"
148-
),
149-
feature(ip_in_core)
150-
)]
151-
#![cfg_attr(
152-
all(not(feature = "std"), feature = "unstable"),
153-
feature(error_in_core)
154-
)]
155151

156152
pub use form_urlencoded;
157153

@@ -165,11 +161,6 @@ extern crate alloc;
165161
#[cfg(not(feature = "alloc"))]
166162
compile_error!("the `alloc` feature must be enabled");
167163

168-
#[cfg(not(any(feature = "no_std_net", feature = "std", feature = "unstable")))]
169-
compile_error!(
170-
"Either the `no_std_net`, `std` or, on nightly, the `unstable` feature, must be enabled"
171-
);
172-
173164
#[cfg(feature = "serde")]
174165
extern crate serde;
175166

@@ -180,13 +171,11 @@ use crate::parser::{
180171
};
181172
use percent_encoding::utf8_percent_encode;
182173
use core::borrow::Borrow;
183-
use core::cmp;
184-
use core::fmt::{self, Write};
185-
use core::hash;
174+
use core::fmt::Write;
186175
#[cfg(feature = "std")]
187176
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
188177
use std::io;
189-
use core::mem;
178+
use core::{cmp, fmt, hash, mem};
190179
use crate::net::IpAddr;
191180
#[cfg(feature = "std")]
192181
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
@@ -196,7 +185,7 @@ use alloc::str;
196185
use alloc::string::{String, ToString};
197186
use alloc::borrow::ToOwned;
198187
#[cfg(feature = "std")]
199-
use std::path::{Path, PathBuf};
188+
use std::path::PathBuf;
200189
use core::convert::TryFrom;
201190

202191
/// `std` version of `net`
@@ -2564,7 +2553,7 @@ impl Url {
25642553
any(unix, windows, target_os = "redox", target_os = "wasi")
25652554
))]
25662555
#[allow(clippy::result_unit_err)]
2567-
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
2556+
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
25682557
let mut serialization = "file://".to_owned();
25692558
let host_start = serialization.len() as u32;
25702559
let (host_end, host) = path_to_file_url_segments(path.as_ref(), &mut serialization)?;
@@ -2606,7 +2595,7 @@ impl Url {
26062595
any(unix, windows, target_os = "redox", target_os = "wasi")
26072596
))]
26082597
#[allow(clippy::result_unit_err)]
2609-
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
2598+
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
26102599
let mut url = Url::from_file_path(path)?;
26112600
if !url.serialization.ends_with('/') {
26122601
url.serialization.push('/')
@@ -2728,7 +2717,7 @@ impl Url {
27282717
any(unix, windows, target_os = "redox", target_os = "wasi")
27292718
))]
27302719
#[allow(clippy::result_unit_err)]
2731-
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
2720+
pub fn to_file_path(&self) -> Result<std::path::PathBuf, ()> {
27322721
if let Some(segments) = self.path_segments() {
27332722
let host = match self.host() {
27342723
None | Some(Host::Domain("localhost")) => None,
@@ -2932,9 +2921,10 @@ impl<'de> serde::Deserialize<'de> for Url {
29322921

29332922
#[cfg(all(feature = "std", any(unix, target_os = "redox", target_os = "wasi")))]
29342923
fn path_to_file_url_segments(
2935-
path: &Path,
2924+
path: &std::path::Path,
29362925
serialization: &mut String,
29372926
) -> Result<(u32, HostInternal), ()> {
2927+
use parser::SPECIAL_PATH_SEGMENT;
29382928
use percent_encoding::percent_encode;
29392929
#[cfg(any(unix, target_os = "redox"))]
29402930
use std::os::unix::prelude::OsStrExt;
@@ -2963,7 +2953,7 @@ fn path_to_file_url_segments(
29632953

29642954
#[cfg(all(feature = "std", windows))]
29652955
fn path_to_file_url_segments(
2966-
path: &Path,
2956+
path: &std::path::Path,
29672957
serialization: &mut String,
29682958
) -> Result<(u32, HostInternal), ()> {
29692959
path_to_file_url_segments_windows(path, serialization)
@@ -2972,8 +2962,9 @@ fn path_to_file_url_segments(
29722962
#[cfg(feature = "std")]
29732963
// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
29742964
#[cfg_attr(not(windows), allow(dead_code))]
2965+
#[cfg(feature = "std")]
29752966
fn path_to_file_url_segments_windows(
2976-
path: &Path,
2967+
path: &std::path::Path,
29772968
serialization: &mut String,
29782969
) -> Result<(u32, HostInternal), ()> {
29792970
use crate::parser::PATH_SEGMENT;
@@ -3048,6 +3039,7 @@ fn file_url_segments_to_pathbuf(
30483039
use std::os::unix::prelude::OsStrExt;
30493040
#[cfg(target_os = "wasi")]
30503041
use std::os::wasi::prelude::OsStrExt;
3042+
use std::path::PathBuf;
30513043

30523044
if host.is_some() {
30533045
return Err(());
@@ -3087,13 +3079,14 @@ fn file_url_segments_to_pathbuf(
30873079
fn file_url_segments_to_pathbuf(
30883080
host: Option<&str>,
30893081
segments: str::Split<char>,
3090-
) -> Result<PathBuf, ()> {
3082+
) -> Result<std::path::PathBuf, ()> {
30913083
file_url_segments_to_pathbuf_windows(host, segments)
30923084
}
30933085

30943086
#[cfg(feature = "std")]
30953087
// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
30963088
#[cfg_attr(not(windows), allow(dead_code))]
3089+
#[cfg(feature = "std")]
30973090
fn file_url_segments_to_pathbuf_windows(
30983091
host: Option<&str>,
30993092
mut segments: str::Split<'_, char>,
@@ -3138,7 +3131,7 @@ fn file_url_segments_to_pathbuf_windows(
31383131
Err(..) => return Err(()),
31393132
}
31403133
}
3141-
let path = PathBuf::from(string);
3134+
let path = std::path::PathBuf::from(string);
31423135
debug_assert!(
31433136
path.is_absolute(),
31443137
"to_file_path() failed to produce an absolute Path"

url/src/origin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use crate::host::Host;
1010
use crate::parser::default_port;
1111
use crate::Url;
12-
use alloc::{borrow::ToOwned, string::String};
12+
use alloc::borrow::ToOwned;
13+
use alloc::format;
14+
use alloc::string::String;
1315
use core::sync::atomic::{AtomicUsize, Ordering};
1416

1517
pub fn url_origin(url: &Url) -> Origin {

url/src/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use alloc::string::{String, ToString};
9+
use alloc::string::String;
10+
use alloc::string::ToString;
1011
use core::fmt::{self, Formatter, Write};
1112
use core::str;
1213

url/src/quirks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//! Unless you need to be interoperable with web browsers,
1212
//! you probably want to use `Url` method instead.
1313
14-
use alloc::string::{String, ToString};
15-
1614
use crate::parser::{default_port, Context, Input, Parser, SchemeType};
1715
use crate::{Host, ParseError, Position, Url};
16+
use alloc::string::String;
17+
use alloc::string::ToString;
1818

1919
/// Internal components / offsets of a URL.
2020
///

0 commit comments

Comments
 (0)