use our_string::comrades::{RcBytes, ArcBytes}; #[test] fn test_traits() { macro_rules! assert_impl { ($t:ty : $($tr:tt)*) => {{ fn checker() {} checker::<$t>(); }}; } macro_rules! assert_not_impl { ($t:ty : $($tr:tt)*) => { const _: fn() -> () = || { struct Check(T); trait Foo { fn foo() {} } impl Foo<()> for Check {} impl Foo for Check {} as Foo<_>>::foo() }; }; } assert_impl!(std::sync::Arc<[u8]> : Send + Sync); assert_not_impl!(std::rc::Rc<[u8]> : Send); assert_not_impl!(std::rc::Rc<[u8]> : Sync); assert_impl!(ArcBytes : Send + Sync + core::fmt::Debug + Default + Clone + PartialEq + Eq + PartialOrd + Ord + core::ops::Deref + AsRef<[u8]> + core::borrow::Borrow<[u8]> + core::hash::Hash); assert_impl!(RcBytes : core::fmt::Debug + Default + Clone + PartialEq + Eq + PartialOrd + Ord + core::ops::Deref + AsRef<[u8]> + core::borrow::Borrow<[u8]> + core::hash::Hash); assert_not_impl!(RcBytes : Send); assert_not_impl!(RcBytes : Sync); } #[test] fn test_rc_bytes() { assert_eq!(size_of::(), size_of::()); assert_eq!(size_of::>(), size_of::()); for value in ["".as_bytes(), b"h", b"he", b"hel", b"help", b"help me obi-wan kenobi, you're my only hope"] { let v = RcBytes::from(value); assert_eq!(v, value); assert_eq!(&*v, value); assert_ne!(v.as_ptr(), value.as_ptr()); let vv = v.clone(); assert_eq!(vv, value); assert_eq!(&*vv, value); assert_ne!(v.as_ptr(), value.as_ptr()); assert_eq!(v.as_ptr(), vv.as_ptr()); drop(v); assert_eq!(vv, value); assert_eq!(&*vv, value); } let empty = RcBytes::default(); assert_eq!(empty.is_empty(), true); assert_eq!(empty, &[] as &[u8]); } #[test] fn test_arc_bytes() { assert_eq!(size_of::(), size_of::()); assert_eq!(size_of::>(), size_of::()); for value in ["".as_bytes(), b"h", b"he", b"hel", b"help", b"help me obi-wan kenobi, you're my only hope"] { let v = ArcBytes::from(value); assert_eq!(v, value); assert_eq!(&*v, value); assert_ne!(v.as_ptr(), value.as_ptr()); let vv = v.clone(); assert_eq!(vv, value); assert_eq!(&*vv, value); assert_ne!(v.as_ptr(), value.as_ptr()); assert_eq!(v.as_ptr(), vv.as_ptr()); drop(v); assert_eq!(vv, value); assert_eq!(&*vv, value); std::thread::spawn(move || { assert_eq!(vv, value); assert_eq!(&*vv, value); }); } let empty = ArcBytes::default(); assert_eq!(empty.is_empty(), true); assert_eq!(empty, &[] as &[u8]); }