diff --git a/Cargo.toml b/Cargo.toml index 291c54f..20b7825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,12 +21,13 @@ homepage = "https://github.com/thomcc/arcstr" include = ["src/**/*", "LICENSE-*", "README.md"] [features] -std = [] +std = ["portable-atomic/std"] default = ["substr"] substr = [] substr-usize-indices = ["substr"] [dependencies] +portable-atomic = { version = "1", default-features = false } serde = { version = "1", default-features = false, optional = true } [dev-dependencies] diff --git a/src/arc_str.rs b/src/arc_str.rs index 4497198..80aa9a3 100644 --- a/src/arc_str.rs +++ b/src/arc_str.rs @@ -9,10 +9,10 @@ use core::alloc::Layout; use core::mem::{align_of, size_of, MaybeUninit}; use core::ptr::NonNull; -#[cfg(not(all(loom, test)))] -pub(crate) use core::sync::atomic::{AtomicUsize, Ordering}; #[cfg(all(loom, test))] pub(crate) use loom::sync::atomic::{AtomicUsize, Ordering}; +#[cfg(not(all(loom, test)))] +pub(crate) use portable_atomic::{AtomicUsize, Ordering}; #[cfg(feature = "substr")] use crate::Substr; @@ -1378,6 +1378,7 @@ impl From for alloc::rc::Rc { s.as_str().into() } } +#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From for alloc::sync::Arc { #[inline] fn from(s: ArcStr) -> Self { @@ -1390,6 +1391,7 @@ impl From> for ArcStr { Self::from(&*s) } } +#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for ArcStr { #[inline] fn from(s: alloc::sync::Arc) -> Self { @@ -1480,6 +1482,7 @@ macro_rules! impl_peq { )+}; } +#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl_peq! { (ArcStr, str), (ArcStr, &'a str), @@ -1492,6 +1495,17 @@ impl_peq! { (ArcStr, alloc::rc::Rc), } +#[cfg(not(all(not(no_rc), not(no_sync), target_has_atomic = "ptr")))] +impl_peq! { + (ArcStr, str), + (ArcStr, &'a str), + (ArcStr, String), + (ArcStr, Cow<'a, str>), + (ArcStr, Box), + (ArcStr, alloc::rc::Rc), + (ArcStr, alloc::rc::Rc), +} + impl PartialOrd for ArcStr { #[inline] fn partial_cmp(&self, s: &Self) -> Option {