From 45f0fdcbe07057d74d4ed9dd3f62e0592e17e7ce Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 15 Oct 2022 15:11:51 +0800 Subject: [PATCH] no_std = no_time. --- .github/workflows/build.yml | 5 +++-- Cargo.toml | 4 ++-- src/api/definitions/mod.rs | 1 - src/api/type_names.rs | 1 - src/lib.rs | 1 - src/packages/mod.rs | 1 - src/packages/pkg_std.rs | 2 +- src/packages/time_basic.rs | 1 - src/serde/de.rs | 1 - src/serde/serialize.rs | 2 -- src/types/dynamic.rs | 20 -------------------- src/types/mod.rs | 1 - 12 files changed, 6 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a72d1d4..6823d676 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,10 +60,11 @@ jobs: - "--features no_object,serde,metadata,internals,debugging" - "--features no_function,serde,metadata,internals,debugging" - "--features no_module,serde,metadata,internals,debugging" + - "--features no_time,serde,metadata,internals,debugging" - "--features no_closure,serde,metadata,internals,debugging" - "--features unicode-xid-ident,serde,metadata,internals,debugging" - - "--features sync,no_function,no_float,no_position,no_optimize,no_module,no_closure,no_custom_syntax,metadata,serde,unchecked,debugging" - - "--features no_function,no_float,no_position,no_index,no_object,no_optimize,no_module,no_closure,no_custom_syntax,unchecked" + - "--features sync,no_time,no_function,no_float,no_position,no_optimize,no_module,no_closure,no_custom_syntax,metadata,serde,unchecked,debugging" + - "--features no_time,no_function,no_float,no_position,no_index,no_object,no_optimize,no_module,no_closure,no_custom_syntax,unchecked" toolchain: [stable] experimental: [false] include: diff --git a/Cargo.toml b/Cargo.toml index ff8a8b69..e1f3bd4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,11 +53,11 @@ only_i64 = [] # set INT=i64 (default) and disable support for decimal = ["rust_decimal"] # add the Decimal number type no_index = [] # no arrays and indexing no_object = [] # no custom objects +no_time = [] # no timestamps no_function = ["no_closure"] # no script-defined functions (meaning no closures) no_closure = [] # no automatic sharing and capture of anonymous functions to external variables no_module = [] # no modules no_custom_syntax = [] # no custom syntax or custom operators -no_time = [] # no timestamps unicode-xid-ident = ["unicode-xid"] # allow Unicode Standard Annex #31 for identifiers. metadata = ["serde", "serde_json", "rhai_codegen/metadata", "smartstring/serde"] # enable exporting functions metadata internals = [] # expose internal data structures @@ -65,7 +65,7 @@ debugging = ["internals"] # enable debugging serde = ["dep:serde", "smartstring/serde", "smallvec/serde"] # implement serde for rhai types # compiling for no-std -no_std = ["no-std-compat", "num-traits/libm", "core-error", "libm", "hashbrown"] +no_std = ["no-std-compat", "num-traits/libm", "core-error", "libm", "hashbrown", "no_time"] # compiling for WASM wasm-bindgen = ["instant/wasm-bindgen"] diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index 4ac1280d..7be44611 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -555,7 +555,6 @@ fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> { #[cfg(not(feature = "no_object"))] let ty = ty.replace(type_name::(), "Map"); - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] let ty = ty.replace(type_name::(), "Instant"); diff --git a/src/api/type_names.rs b/src/api/type_names.rs index eb0f9857..f7897bf0 100644 --- a/src/api/type_names.rs +++ b/src/api/type_names.rs @@ -44,7 +44,6 @@ fn map_std_type_name(name: &str, shorthands: bool) -> &str { if name == type_name::() || name == "Map" { return if shorthands { "map" } else { "Map" }; } - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] if name == type_name::() || name == "Instant" { return if shorthands { "timestamp" } else { "Instant" }; diff --git a/src/lib.rs b/src/lib.rs index 9a540e3a..199edb75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,7 +204,6 @@ pub use eval::EvalContext; pub use func::{NativeCallContext, RegisterNativeFunction}; pub use module::{FnNamespace, Module}; pub use tokenizer::Position; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] pub use types::Instant; pub use types::{ diff --git a/src/packages/mod.rs b/src/packages/mod.rs index c9f31bcf..499a1762 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -38,7 +38,6 @@ pub use pkg_core::CorePackage; pub use pkg_std::StandardPackage; pub use string_basic::BasicStringPackage; pub use string_more::MoreStringPackage; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] pub use time_basic::BasicTimePackage; diff --git a/src/packages/pkg_std.rs b/src/packages/pkg_std.rs index cdc5fbbf..b054b3ae 100644 --- a/src/packages/pkg_std.rs +++ b/src/packages/pkg_std.rs @@ -26,7 +26,7 @@ def_package! { #[cfg(not(feature = "no_index"))] BasicArrayPackage, #[cfg(not(feature = "no_index"))] BasicBlobPackage, #[cfg(not(feature = "no_object"))] BasicMapPackage, - #[cfg(all(not(feature = "no_std"), not(feature = "no_time")))] BasicTimePackage, + #[cfg(not(feature = "no_time"))] BasicTimePackage, MoreStringPackage { lib.standard = true; diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index e76cc06e..cf7f3dc4 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -1,4 +1,3 @@ -#![cfg(not(feature = "no_std"))] #![cfg(not(feature = "no_time"))] use super::arithmetic::make_err as make_arithmetic_err; diff --git a/src/serde/de.rs b/src/serde/de.rs index 4dd0b133..fcb26a9d 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -156,7 +156,6 @@ impl<'de> Deserializer<'de> for DynamicDeserializer<'de> { #[cfg(not(feature = "no_object"))] Union::Map(..) => self.deserialize_map(visitor), Union::FnPtr(..) => self.type_error(), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => self.type_error(), diff --git a/src/serde/serialize.rs b/src/serde/serialize.rs index 509dad56..424de0d5 100644 --- a/src/serde/serialize.rs +++ b/src/serde/serialize.rs @@ -9,7 +9,6 @@ use std::prelude::v1::*; #[cfg(not(feature = "no_object"))] use serde::ser::SerializeMap; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] use crate::types::dynamic::Variant; @@ -66,7 +65,6 @@ impl Serialize for Dynamic { map.end() } Union::FnPtr(ref f, ..) => ser.serialize_str(f.fn_name()), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(ref x, ..) => ser.serialize_str(x.as_ref().type_name()), diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index 5643901a..0c9b7661 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -14,12 +14,10 @@ use std::{ pub use super::Variant; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] #[cfg(not(target_family = "wasm"))] pub use std::time::Instant; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] #[cfg(target_family = "wasm")] pub use instant::Instant; @@ -86,7 +84,6 @@ pub enum Union { /// A function pointer. FnPtr(Box, Tag, AccessMode), /// A timestamp value. - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] TimeStamp(Box, Tag, AccessMode), @@ -197,7 +194,6 @@ impl Dynamic { Union::Array(_, tag, _) | Union::Blob(_, tag, _) => tag, #[cfg(not(feature = "no_object"))] Union::Map(_, tag, _) => tag, - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(_, tag, _) => tag, #[cfg(not(feature = "no_closure"))] @@ -223,7 +219,6 @@ impl Dynamic { Union::Array(_, ref mut tag, _) | Union::Blob(_, ref mut tag, _) => *tag = value, #[cfg(not(feature = "no_object"))] Union::Map(_, ref mut tag, _) => *tag = value, - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(_, ref mut tag, _) => *tag = value, #[cfg(not(feature = "no_closure"))] @@ -296,7 +291,6 @@ impl Dynamic { if TypeId::of::() == TypeId::of::() { return matches!(self.0, Union::FnPtr(..)); } - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] if TypeId::of::() == TypeId::of::() { return matches!(self.0, Union::TimeStamp(..)); @@ -329,7 +323,6 @@ impl Dynamic { #[cfg(not(feature = "no_object"))] Union::Map(..) => TypeId::of::(), Union::FnPtr(..) => TypeId::of::(), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => TypeId::of::(), @@ -364,7 +357,6 @@ impl Dynamic { #[cfg(not(feature = "no_object"))] Union::Map(..) => "map", Union::FnPtr(..) => "Fn", - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => "timestamp", @@ -415,7 +407,6 @@ impl Hash for Dynamic { Union::Variant(..) => unimplemented!("{} cannot be hashed", self.type_name()), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => unimplemented!("{} cannot be hashed", self.type_name()), } @@ -441,7 +432,6 @@ impl fmt::Display for Dynamic { #[cfg(not(feature = "no_object"))] Union::Map(..) => fmt::Debug::fmt(self, f), Union::FnPtr(ref v, ..) => fmt::Display::fmt(v, f), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => f.write_str(""), @@ -547,7 +537,6 @@ impl fmt::Debug for Dynamic { fmt::Debug::fmt(v, f) } Union::FnPtr(ref v, ..) => fmt::Debug::fmt(v, f), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(..) => write!(f, ""), @@ -646,7 +635,6 @@ impl Clone for Dynamic { #[cfg(not(feature = "no_object"))] Union::Map(ref v, tag, ..) => Self(Union::Map(v.clone(), tag, ReadWrite)), Union::FnPtr(ref v, tag, ..) => Self(Union::FnPtr(v.clone(), tag, ReadWrite)), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(ref v, tag, ..) => Self(Union::TimeStamp(v.clone(), tag, ReadWrite)), @@ -889,7 +877,6 @@ impl Dynamic { /// Create a new [`Dynamic`] from an [`Instant`]. /// /// Not available under `no-std` or `no_time`. - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] #[inline(always)] #[must_use] @@ -917,7 +904,6 @@ impl Dynamic { Union::Array(.., access) | Union::Blob(.., access) => access, #[cfg(not(feature = "no_object"))] Union::Map(.., access) => access, - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(.., access) => access, #[cfg(not(feature = "no_closure"))] @@ -955,7 +941,6 @@ impl Dynamic { v.set_access_mode(typ); } } - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(.., ref mut access) => *access = typ, #[cfg(not(feature = "no_closure"))] @@ -1090,7 +1075,6 @@ impl Dynamic { reify!(value, |v: crate::Map| return v.into()); reify!(value, |v: FnPtr| return v.into()); - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] reify!(value, |v: Instant| return v.into()); #[cfg(not(feature = "no_closure"))] @@ -1184,7 +1168,6 @@ impl Dynamic { #[cfg(not(feature = "no_object"))] Union::Map(v, ..) => reify!(*v => Option), Union::FnPtr(v, ..) => reify!(*v => Option), - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] Union::TimeStamp(v, ..) => reify!(*v => Option), Union::Unit(v, ..) => reify!(v => Option), @@ -1484,7 +1467,6 @@ impl Dynamic { _ => None, }; } - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] if TypeId::of::() == TypeId::of::() { return match self.0 { @@ -1583,7 +1565,6 @@ impl Dynamic { _ => None, }; } - #[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] if TypeId::of::() == TypeId::of::() { return match self.0 { @@ -1978,7 +1959,6 @@ impl From for Dynamic { Self(Union::FnPtr(value.into(), DEFAULT_TAG_VALUE, ReadWrite)) } } -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] impl From for Dynamic { #[inline(always)] diff --git a/src/types/mod.rs b/src/types/mod.rs index 8de89ca8..b6ca3802 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -14,7 +14,6 @@ pub mod variant; pub use bloom_filter::BloomFilterU64; pub use custom_types::{CustomTypeInfo, CustomTypesCollection}; pub use dynamic::Dynamic; -#[cfg(not(feature = "no_std"))] #[cfg(not(feature = "no_time"))] pub use dynamic::Instant; pub use error::EvalAltResult;