our_string/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3
4extern crate alloc;
5
6/// Represents a socialist data container.
7///
8/// This should only be implemented on types that have semantics similar to [`Rc`](alloc::rc::Rc) or [`Arc`](alloc::sync::Arc).
9pub trait Comrade {
10    fn from_slice(s: &[u8]) -> Self;
11    fn as_slice(&self) -> &[u8];
12}
13
14macro_rules! impl_comrade {
15    ($($(#[$a:meta])* $t:ident$(::$tt:ident)*),*) => {$(
16        $(#[$a])* impl<T: core::ops::Deref<Target = [u8]> + for<'a> From<&'a [u8]>> Comrade for $t$(::$tt)*<T> {
17            fn from_slice(s: &[u8]) -> Self { $t$(::$tt)*::new(T::from(s)) }
18            fn as_slice(&self) -> &[u8] { self }
19        }
20        $(#[$a])* impl Comrade for $t$(::$tt)*<[u8]> {
21            fn from_slice(s: &[u8]) -> Self { $t$(::$tt)*::from(s) }
22            fn as_slice(&self) -> &[u8] { self }
23        }
24    )*};
25}
26impl_comrade! { alloc::rc::Rc, #[cfg(target_has_atomic = "ptr")] alloc::sync::Arc }
27
28mod bytes;
29mod string;
30pub mod comrades;
31
32pub use bytes::*;
33pub use string::*;