Skip to content

Commit

Permalink
Add #![no_std] support
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Aug 12, 2021
1 parent cd87249 commit c306ed3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ fn try_main() -> Result<()> {
cwd.display()
);

{
let _s = Section::new("BUILD_NO_DEFAULT_FEATURES");
shell("cargo test --all-features --workspace --no-run --no-default-features")?;
}

{
let _s = Section::new("BUILD");
shell("cargo test --all-features --workspace --no-run")?;
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
edition = "2018"

[dependencies]
serde = { version = "1", optional = true, default_features = false, features = [ "std" ] }
serde = { version = "1", optional = true, default_features = false }
arbitrary = { version = "1", optional = true }

[dev-dependencies]
proptest = "0.10"
serde_json = "1"
serde = { version = "1", features = [ "derive" ] }

[features]
default = ["std"]
std = ["serde/std"]
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate core as std;

#[cfg(not(feature = "std"))]
extern crate alloc;

use std::{
borrow::Borrow,
cmp::{self, Ordering},
fmt, hash, iter,
ops::Deref,
};

#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
sync::Arc,
};

#[cfg(feature = "std")]
use std::sync::Arc;

/// A `SmolStr` is a string type that has the following properties:
///
/// * `size_of::<SmolStr>() == size_of::<String>()`
Expand Down

0 comments on commit c306ed3

Please sign in to comment.