Skip to content

Commit 45d15c5

Browse files
bors[bot]ark0f
andauthored
36: Add `#![no_std]` support r=matklad a=ark0f Co-authored-by: Arsenii Lyashenko <arsenylyashenko.3@gmail.com>
2 parents 428c2f5 + 9dbc8b8 commit 45d15c5

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/tools/rust-analyzer/lib/smol_str/.github/ci.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ fn try_main() -> Result<()> {
2323
cwd.display()
2424
);
2525

26+
{
27+
let _s = Section::new("BUILD_NO_DEFAULT_FEATURES");
28+
shell("cargo test --all-features --workspace --no-run --no-default-features")?;
29+
}
30+
2631
{
2732
let _s = Section::new("BUILD");
2833
shell("cargo test --all-features --workspace --no-run")?;

src/tools/rust-analyzer/lib/smol_str/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
88
edition = "2018"
99

1010
[dependencies]
11-
serde = { version = "1", optional = true, default_features = false, features = [ "std" ] }
11+
serde = { version = "1", optional = true, default_features = false }
1212
arbitrary = { version = "1", optional = true }
1313

1414
[dev-dependencies]
1515
proptest = "0.10"
1616
serde_json = "1"
1717
serde = { version = "1", features = [ "derive" ] }
18+
19+
[features]
20+
default = ["std"]
21+
std = ["serde/std"]

src/tools/rust-analyzer/lib/smol_str/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
3+
#[cfg(not(feature = "std"))]
4+
extern crate core as std;
5+
6+
#[cfg(not(feature = "std"))]
7+
extern crate alloc;
8+
19
use std::{
210
borrow::Borrow,
311
cmp::{self, Ordering},
412
fmt, hash, iter,
513
ops::Deref,
14+
};
15+
16+
#[cfg(not(feature = "std"))]
17+
use alloc::{
18+
string::{String, ToString},
619
sync::Arc,
720
};
821

22+
#[cfg(feature = "std")]
23+
use std::sync::Arc;
24+
925
/// A `SmolStr` is a string type that has the following properties:
1026
///
1127
/// * `size_of::<SmolStr>() == size_of::<String>()`

0 commit comments

Comments
 (0)