From 5ec9191e385a2010943e2dd5179db712dfa0b2bc Mon Sep 17 00:00:00 2001 From: GrayJack Date: Sun, 19 Jan 2025 00:17:50 -0300 Subject: [PATCH] feat: always have `no_std` and import std when `std` feature is activated --- .vscode/settings.json | 5 +++++ src/lib.rs | 5 ++++- src/types.rs | 1 - src/types/buffer.rs | 1 - src/types/string.rs | 1 - 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ae7a6338c..46eba5d9d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,13 @@ { + "rust-analyzer.cargo.extraEnv": { + "CFLAGS": "", + "CXXFLAGS": "" + }, "rust-analyzer.checkOnSave.features": ["amalgation", "nightly"], "rust-analyzer.cargo.features": [ "amalgation", "nightly" ], + "rust-analyzer.imports.preferNoStd": true, "rust-analyzer.completion.snippets.custom": { "JanetRS Test": { "prefix": ["janetrstest", "test"], diff --git a/src/lib.rs b/src/lib.rs index 3b4dbbe8f5..6450d89315 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ //! ### TODO: Lib level //! - Better docs. //! - Marshalling mechanism -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![cfg_attr(feature = "nightly", feature(allocator_api))] #![cfg_attr(docsrs, feature(doc_cfg))] @@ -67,6 +67,9 @@ compile_error!(r#"You can only use either "amalgation" or "system" feature, not // Janet requires allocation extern crate alloc; +#[cfg(any(test, feature = "std"))] +extern crate std; + /// This module has a expose the entire Janet C-API structures, constants and functions. /// /// This module exists in the case of a functionality of the Janet C-API can't be, or is diff --git a/src/types.rs b/src/types.rs index b8a148be5d..8958b2874e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -12,7 +12,6 @@ use core::{ num::ParseIntError, }; -#[cfg(not(feature = "std"))] use alloc::{ string::{String, ToString}, vec, diff --git a/src/types/buffer.rs b/src/types/buffer.rs index a0f1c5ca83..b89855f5a0 100644 --- a/src/types/buffer.rs +++ b/src/types/buffer.rs @@ -11,7 +11,6 @@ use core::{ use alloc::borrow::Cow; -#[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; #[cfg(feature = "std")] diff --git a/src/types/string.rs b/src/types/string.rs index 933db580f5..9fc73d1fde 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -9,7 +9,6 @@ use core::{ use alloc::borrow::Cow; -#[cfg(not(feature = "std"))] use alloc::string::String; #[cfg(feature = "std")]