Skip to content

Commit

Permalink
Hide special Arc handling behind a (lack of a) feature
Browse files Browse the repository at this point in the history
  • Loading branch information
someguynamedjosh committed Aug 8, 2022
1 parent bd6dd4c commit d19289b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ouroboros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 3 additions & 0 deletions ouroboros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,11 @@ pub mod macro_help {
}

std_type_check!(is_std_box_type T alloc::boxed::Box<T>);
#[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<T>);
#[cfg(feature = "std")]
std_type_check!(is_std_arc_type T alloc::sync::Arc<T>);
std_type_check!(is_std_rc_type T alloc::rc::Rc<T>);

pub fn aliasable_boxed<T>(data: T) -> AliasableBox<T> {
Expand Down
3 changes: 3 additions & 0 deletions ouroboros_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
3 changes: 3 additions & 0 deletions ouroboros_macro/src/covariance_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions ouroboros_macro/src/generate/type_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand Down

0 comments on commit d19289b

Please sign in to comment.