1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![no_std]
#![forbid(unsafe_code)]

#![doc = include_str!("../README.md")]

extern crate alloc;

mod private {
    pub trait Sealed {}
    impl<T: ?Sized> Sealed for alloc::rc::Rc<T> {}
    #[cfg(target_has_atomic = "ptr")]
    impl<T: ?Sized> Sealed for alloc::sync::Arc<T> {}
}

macro_rules! comrade {
    ($n:ident : $r:ty) => {
        comrade! { $n : $r : alloc::rc::Rc, #[cfg(target_has_atomic = "ptr")] alloc::sync::Arc }
    };
    ($n:ident : $r:ty : $($(#[$a:meta])* $t:ident$(::$tt:ident)*),*) => {
        /// Represents a socialist data container.
        ///
        /// This trait has been sealed away by the People to ensure it cannot be implemented on capitalist types like [`Box`](alloc::boxed::Box) and [`Vec`](alloc::vec::Vec).
        pub trait $n: crate::private::Sealed {
            fn from_slice(s: &$r) -> Self;
            fn as_slice(&self) -> &$r;
        }
        $(
            $(#[$a])* impl<T: core::ops::Deref<Target = $r> + for<'a> From<&'a $r>> $n for $t$(::$tt)*<T> {
                fn from_slice(s: &$r) -> Self { $t$(::$tt)*::new(T::from(s)) }
                fn as_slice(&self) -> &$r { self }
            }
            $(#[$a])* impl $n for $t$(::$tt)*<$r> {
                fn from_slice(s: &$r) -> Self { $t$(::$tt)*::from(s) }
                fn as_slice(&self) -> &$r { self }
            }
        )*
    };
}

#[derive(Clone)]
enum OurInner<T, const N: usize> {
    Inline { len: core::num::NonZero<u8>, content: [u8; N] },
    Outline { content: T },
}

mod bytes;
mod string;

pub use bytes::*;
pub use string::*;