diff --git a/ouroboros/Cargo.toml b/ouroboros/Cargo.toml index 943fc24..60377da 100644 --- a/ouroboros/Cargo.toml +++ b/ouroboros/Cargo.toml @@ -12,3 +12,7 @@ repository = "https://github.com/joshua-maros/ouroboros" [dependencies] aliasable = "0.1.3" ouroboros_macro = { version = "0.15.1", path = "../ouroboros_macro" } + +[features] +default = ["std"] +std = ["ouroboros_macro/std"] diff --git a/ouroboros/src/lib.rs b/ouroboros/src/lib.rs index 87e50ac..a50251f 100644 --- a/ouroboros/src/lib.rs +++ b/ouroboros/src/lib.rs @@ -365,8 +365,11 @@ pub mod macro_help { } std_type_check!(is_std_box_type T alloc::boxed::Box); + #[cfg(not(feature = "std"))] #[cfg(target_has_atomic = "ptr")] // alloc::sync is missing if this is false std_type_check!(is_std_arc_type T alloc::sync::Arc); + #[cfg(feature = "std")] + std_type_check!(is_std_arc_type T alloc::sync::Arc); std_type_check!(is_std_rc_type T alloc::rc::Rc); pub fn aliasable_boxed(data: T) -> AliasableBox { diff --git a/ouroboros_macro/Cargo.toml b/ouroboros_macro/Cargo.toml index c686425..c4701f3 100644 --- a/ouroboros_macro/Cargo.toml +++ b/ouroboros_macro/Cargo.toml @@ -17,3 +17,6 @@ proc-macro2 = "1.0" proc-macro-error = "1.0.4" quote = "1.0" syn = { version = "1.0", features = ["full"] } + +[features] +std = [] diff --git a/ouroboros_macro/src/covariance_detection.rs b/ouroboros_macro/src/covariance_detection.rs index 2f50983..8c38f4b 100644 --- a/ouroboros_macro/src/covariance_detection.rs +++ b/ouroboros_macro/src/covariance_detection.rs @@ -3,7 +3,10 @@ use syn::{GenericArgument, PathArguments, Type}; use crate::utils::uses_this_lifetime; +#[cfg(feature = "std")] const STD_CONTAINER_TYPES: &[&str] = &["Box", "Arc", "Rc"]; +#[cfg(not(feature = "std"))] +const STD_CONTAINER_TYPES: &[&str] = &["Box", "Rc"]; /// Returns Some((type_name, element_type)) if the provided type appears to be Box, Arc, or Rc from /// the standard library. Returns None if not. diff --git a/ouroboros_macro/src/generate/type_asserts.rs b/ouroboros_macro/src/generate/type_asserts.rs index 3c8c7d1..c66d1f4 100644 --- a/ouroboros_macro/src/generate/type_asserts.rs +++ b/ouroboros_macro/src/generate/type_asserts.rs @@ -19,6 +19,7 @@ pub fn make_type_asserts(info: &StructInfo) -> TokenStream { if let Some((std_type, _eltype)) = apparent_std_container_type(field_type) { let checker_name = match std_type { "Box" => "is_std_box_type", + #[cfg(feature = "std")] "Arc" => "is_std_arc_type", "Rc" => "is_std_rc_type", _ => unreachable!(),