Skip to content

Commit 32e2c47

Browse files
committed
Make form_urlencoded no_std compatible
1 parent f868c04 commit 32e2c47

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

form_urlencoded/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "form_urlencoded"
33
version = "1.1.0"
44
authors = ["The rust-url developers"]
55
description = "Parser and serializer for the application/x-www-form-urlencoded syntax, as used by HTML forms."
6+
categories = ["no_std"]
67
repository = "https://github.com/servo/rust-url"
78
license = "MIT OR Apache-2.0"
89
edition = "2018"
@@ -11,5 +12,10 @@ rust-version = "1.51"
1112
[lib]
1213
test = false
1314

15+
[features]
16+
default = ["std"]
17+
std = ["alloc"]
18+
alloc = []
19+
1420
[dependencies]
1521
percent-encoding = { version = "2.2.0", path = "../percent_encoding" }

form_urlencoded/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@
1212
//!
1313
//! Converts between a string (such as an URL’s query string)
1414
//! and a sequence of (name, value) pairs.
15+
#![no_std]
1516

17+
// For forwards compatibility
18+
#[cfg(feature = "std")]
19+
extern crate std as _;
20+
21+
extern crate alloc;
22+
23+
#[cfg(not(feature = "alloc"))]
24+
compile_error!("the `alloc` feature must currently be enabled");
25+
26+
use alloc::borrow::{Borrow, Cow, ToOwned};
27+
use alloc::string::String;
28+
use core::str;
1629
use percent_encoding::{percent_decode, percent_encode_byte};
17-
use std::borrow::{Borrow, Cow};
18-
use std::str;
1930

2031
/// Convert a byte string in the `application/x-www-form-urlencoded` syntax
2132
/// into a iterator of (name, value) pairs.

0 commit comments

Comments
 (0)