Skip to content

Commit

Permalink
remove std features (#71)
Browse files Browse the repository at this point in the history
* remove scale_info and re-export PortableRegistry

* remove std features and make no_std

* fix clippy + doc links

* fix more nits

* run tests with all-features

* move extern crate std to lib.rs
  • Loading branch information
niklasad1 authored Nov 15, 2024
1 parent 39a39fc commit e59576d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
uses: actions-rs/[email protected]
with:
command: test
args: --all-targets --workspace
args: --all-targets --all-features --workspace

- name: Cargo test docs
uses: actions-rs/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
rust-version = "1.81.0"

[features]
default = ["std", "serde", "from-string", "parser-ss58"]
default = ["serde", "from-string", "parser-ss58"]

# Only work in "std" environments:
std = ["scale-bits/std", "either/use_std", "serde?/std", "serde_json/std"]
# Internal feature for tests that needs std.
__std = []

# Enable support for parsing strings into Values.
from-string = ["dep:yap"]
Expand Down
2 changes: 1 addition & 1 deletion src/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{Composite, Value, ValueDef, Variant};
use crate::prelude::*;

/// This trait allows indexing into [`Value`]s (and options of [`Value`]s)
/// using the [`At::at()`] function. It's a little like Rust's [`::std::ops::Index`]
/// using the [`At::at()`] function. It's a little like Rust's [`core::ops::Index`]
/// trait, but adapted so that we can return and work with optionals.
///
/// Indexing into a [`Value`] never panics; instead it will return `None` if a
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ of JSON data).
- Accessed ergonomically via the [`At`] trait.
*/
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

extern crate alloc;

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

mod at;
mod macros;
mod prelude;
Expand Down
8 changes: 1 addition & 7 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@
// from `core` or `alloc`.
pub use prelude_contents::*;

#[cfg(feature = "std")]
mod prelude_contents {
pub use std::prelude::rust_2021::*;
}

#[cfg(not(feature = "std"))]
mod prelude_contents {
pub use core::prelude::rust_2021::*;

// The core prelude doesn't include things from
// `alloc` by default, so add the ones we need that
// are otherwose exposed via the std prelude.
// are otherwise exposed via the std prelude.
pub use alloc::borrow::ToOwned;
pub use alloc::string::{String, ToString};
pub use alloc::vec::Vec;
Expand Down
3 changes: 1 addition & 2 deletions src/scale_impls/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ mod test {
let scale_info::TypeDef::Composite(c) = &types.resolve(id).unwrap().type_def else {
panic!("Couldn't get fields");
};
let mut fields =
c.fields.iter().map(|f| scale_decode::Field::new(f.ty.id, f.name.as_deref()));
let mut fields = c.fields.iter().map(|f| scale_decode::Field::new(f.ty.id, f.name));

// get some bytes to decode from:
let foo = Foo { a: "Hello".to_owned(), b: true, c: 123 };
Expand Down
9 changes: 4 additions & 5 deletions src/scale_impls/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,11 @@ mod test {
use super::*;
use crate::value;
use codec::{Compact, Encode};
use core::time::Duration;
use scale_info::PortableRegistry;

// Panic after some duration.
#[cfg(feature = "std")]
fn panic_after<T, F>(d: Duration, f: F) -> T
#[cfg(feature = "__std")]
fn panic_after<T, F>(d: core::time::Duration, f: F) -> T
where
T: Send + 'static,
F: FnOnce() -> T,
Expand Down Expand Up @@ -631,9 +630,9 @@ mod test {
// Prior to https://github.com/paritytech/scale-value/pulls/48, this test will take
// too long and panic. #48 should ensure that this doesn't happen.
#[test]
#[cfg(feature = "std")]
#[cfg(feature = "__std")]
fn encoding_shouldnt_take_forever() {
panic_after(Duration::from_millis(100), || {
panic_after(core::time::Duration::from_millis(100), || {
#[derive(scale_info::TypeInfo, codec::Encode)]
struct A(bool);

Expand Down

0 comments on commit e59576d

Please sign in to comment.