Skip to content

Commit 070b8a3

Browse files
committed
Make data-url no_std compatible
1 parent 57ea92e commit 070b8a3

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

data-url/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ name = "data-url"
33
version = "0.2.0"
44
authors = ["Simon Sapin <[email protected]>"]
55
description = "Processing of data: URL according to WHATWG’s Fetch Standard"
6+
categories = ["no_std"]
67
repository = "https://github.com/servo/rust-url"
78
license = "MIT OR Apache-2.0"
89
edition = "2018"
910
autotests = false
1011
rust-version = "1.51"
1112

13+
[features]
14+
default = ["std"]
15+
std = ["alloc"]
16+
alloc = []
17+
1218
[dev-dependencies]
1319
tester = "0.9"
1420
serde = {version = "1.0", features = ["derive"]}

data-url/src/forgiving_base64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! <https://infra.spec.whatwg.org/#forgiving-base64-decode>
22
3+
use alloc::vec::Vec;
4+
35
#[derive(Debug)]
46
pub struct InvalidBase64(InvalidBase64Details);
57

data-url/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
//! assert_eq!(body, b"Hello World!");
1515
//! assert!(fragment.is_none());
1616
//! ```
17+
#![no_std]
18+
19+
// For forwards compatibility
20+
#[cfg(feature = "std")]
21+
extern crate std as _;
22+
23+
#[macro_use]
24+
extern crate alloc;
25+
26+
#[cfg(not(feature = "alloc"))]
27+
compile_error!("the `alloc` feature must currently be enabled");
28+
29+
use alloc::{string::String, vec::Vec};
1730

1831
macro_rules! require {
1932
($condition: expr) => {

data-url/src/mime.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::fmt::{self, Write};
2-
use std::str::FromStr;
1+
use alloc::{borrow::ToOwned, string::String, vec::Vec};
2+
use core::fmt::{self, Write};
3+
use core::str::FromStr;
34

45
/// <https://mimesniff.spec.whatwg.org/#mime-type-representation>
56
#[derive(Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)