Skip to content

Commit 2ca96f2

Browse files
KSXGitHubanonrig
andauthored
feat: add no-std support (#42)
* feat: add no-std support * docs: update metadata * fix: implement no-std properly * chore: custom test script * ci: fix * docs: reference related issue * ci: rename a step * refactor: remove unused code * test: serde * docs: remove incorrect feature * docs: features * docs: remove unnecessary `mut` * docs: correct the comment * fix: replace alloc with std * fix: clippy should error on warnings * ci: use cargo-hack * test: libcpp * chore: allow users of test.sh to skip features * docs: libcpp * docs: test.sh --------- Co-authored-by: Yagiz Nizipli <[email protected]>
1 parent 9fc8f69 commit 2ca96f2

File tree

7 files changed

+150
-79
lines changed

7 files changed

+150
-79
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,19 @@ jobs:
4949

5050
- run: rustup show
5151

52-
- name: Cargo Check
53-
run: cargo check --all-targets --all-features --locked
52+
- name: Install cargo-hack
53+
uses: taiki-e/install-action@cargo-hack
5454

55-
- name: Cargo Test
56-
run: cargo test --all-targets --all-features
55+
- name: Clippy
56+
run: cargo hack clippy --feature-powerset -- -D warnings
5757

58-
- name: Cargo Doc
58+
- name: Test
59+
run: cargo hack test --feature-powerset
60+
61+
- name: Check Documentation
5962
env:
6063
RUSTDOCFLAGS: '-D warnings'
61-
run: cargo doc
64+
run: cargo hack doc --feature-powerset
6265

6366
format:
6467
name: Format

Cargo.lock

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ description = "Fast WHATWG Compliant URL parser"
1212
documentation = "https://docs.rs/ada-url"
1313
readme = "README.md"
1414
keywords = ["url", "parser", "whatwg", "performance"]
15-
categories = ["parser-implementations", "web-programming", "encoding"]
16-
repository = "https://ada-url.com"
15+
categories = ["parser-implementations", "web-programming", "encoding", "parsing", "no-std::no-alloc", "no-std"]
16+
repository = "https://github.com/ada-url/rust"
17+
homepage = "https://ada-url.com"
1718
license = "MIT OR Apache-2.0"
1819

1920
[[bench]]
@@ -22,10 +23,13 @@ path = "bench/parse.rs"
2223
harness = false
2324

2425
[features]
26+
default = ["std"]
2527
# pass `cpp_set_stdlib("c++")` to `cc`
2628
libcpp = []
2729
# enables serde serialization/deserialization support
28-
serde = ["dep:serde"]
30+
serde = ["dep:serde", "std"]
31+
# enable allocations
32+
std = []
2933

3034
[dependencies]
3135
derive_more = "0.99.17"

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Here is an example illustrating a common usage:
99
```Rust
1010
use ada_url::Url;
1111
fn main() {
12-
let mut u = Url::parse("http://www.google:8080/love#drug", None).expect("bad url");
12+
let u = Url::parse("http://www.google:8080/love#drug", None).expect("bad url");
1313
println!("port: {:?}", u.port());
1414
println!("hash: {:?}", u.hash());
1515
println!("pathname: {:?}", u.pathname());
@@ -19,6 +19,14 @@ fn main() {
1919
}
2020
```
2121

22+
#### Features
23+
24+
**std:** Functionalities that require `std`. This feature is enabled by default, set `no-default-features` to `true` if you want `no-std`.
25+
26+
**serde:** Allow `Url` to work with `serde`. This feature is disabled by default. Enabling this feature without `std` would provide you only `Serialize`. Enabling this feature and `std` would provide you both `Serialize` and `Deserialize`.
27+
28+
**libcpp:** Build `ada-url` with `libc++`. This feature is disabled by default. Enabling this feature without `libc++` installed would cause compile error.
29+
2230
### Performance
2331

2432
Ada is fast. The benchmark below shows **3.34 times** faster URL parsing compared to `url`
@@ -48,3 +56,21 @@ parse/url time: [6.9266 µs 6.9677 µs 7.0199 µs]
4856
| **[`Deref<Target=str>`](https://doc.rust-lang.org/std/ops/trait.Deref.html)** | Allows for `&Url` to dereference as a `&str`. Also provides a [number of string methods](https://doc.rust-lang.org/std/string/struct.String.html#deref-methods-str) |
4957
| **[`AsRef<[u8]>`](https://doc.rust-lang.org/std/convert/trait.AsRef.html), [`AsRef<str>`](https://doc.rust-lang.org/std/convert/trait.AsRef.html)** | Used to do a cheap reference-to-reference conversion. |
5058
| **[`Send`](https://doc.rust-lang.org/std/marker/trait.Send.html)** | Used to declare that the type can be transferred across thread boundaries. |
59+
60+
### Development
61+
62+
#### `test.sh`
63+
64+
`test.sh` is a convenient helper script that would allow developer to quickly and comprehensively check, lint, and test their code and documentation.
65+
66+
**Basic Usage:**
67+
68+
```sh
69+
./test.sh
70+
```
71+
72+
**Skipping features:**
73+
74+
```sh
75+
SKIP_FEATURES=serde,libcpp ./test.sh
76+
```

bench/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn parse_benchmark(c: &mut Criterion) {
2020
group.bench_function("ada_url", |b| {
2121
b.iter(|| {
2222
URLS.iter().for_each(|url| {
23-
black_box(url).parse::<ada_url::Url>().unwrap();
23+
ada_url::Url::try_from(*black_box(url)).unwrap();
2424
})
2525
})
2626
});

0 commit comments

Comments
 (0)