From 6f4cc91451df2bc9ba1ed4b110b378325ece4f4c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 21 Apr 2022 16:01:20 +0800 Subject: [PATCH] Fix builds. --- src/api/json.rs | 12 +++++++++--- tests/options.rs | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/api/json.rs b/src/api/json.rs index b495c4a0..856e25f4 100644 --- a/src/api/json.rs +++ b/src/api/json.rs @@ -1,7 +1,11 @@ //! Module that defines JSON manipulation functions for [`Engine`]. #![cfg(not(feature = "no_object"))] -use crate::{Engine, LexError, Map, OptimizationLevel, ParseState, RhaiResultOf, Scope, Token}; +use crate::parser::ParseState; +use crate::tokenizer::Token; +use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf, Scope}; +#[cfg(feature = "no_std")] +use std::prelude::v1::*; impl Engine { /// Parse a JSON string into an [object map][Map]. @@ -53,8 +57,7 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[cfg(not(feature = "no_object"))] - #[inline(always)] + #[inline] pub fn parse_json(&self, json: impl AsRef, has_null: bool) -> RhaiResultOf { let scripts = [json.as_ref()]; @@ -134,6 +137,8 @@ impl Engine { /// Return the JSON representation of an [object map][Map]. /// +/// Not available under `no_std`. +/// /// This function can be used together with [`Engine::parse_json`] to work with JSON texts /// without using the [`serde`](https://crates.io/crates/serde) crate (which is heavy). /// @@ -146,6 +151,7 @@ impl Engine { /// # Errors /// /// Data types not supported by JSON serialize into formats that may invalidate the result. +#[inline] pub fn format_map_as_json(map: &Map) -> String { let mut result = String::from('{'); diff --git a/tests/options.rs b/tests/options.rs index f4154d72..aa9b250d 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -112,6 +112,7 @@ fn test_options_strict_var() -> Result<(), Box> { engine.compile("let x = 42; let f = |y| { || x + y };")?; assert!(engine.compile("fn foo() { |y| { || x + y } }").is_err()); } + #[cfg(not(feature = "no_optimize"))] assert_eq!( engine.eval_with_scope::(&mut scope, "fn foo(z) { x * y + z } foo(1)")?, 1