use ::core::ops::Deref;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use alloc::sync::Arc;
pub trait RefCountBackend {
type Shared: Deref<Target = str>;
fn into_raw(shared: Self::Shared) -> *const str;
unsafe fn increment_strong_count(ptr: *const str);
unsafe fn from_raw(ptr: *const str) -> Self::Shared;
fn from_str(s: &str) -> Self::Shared;
fn from_string(s: String) -> Self::Shared;
fn from_boxed_str(s: Box<str>) -> Self::Shared;
}
pub enum LocalBackend {}
impl RefCountBackend for LocalBackend {
type Shared = Rc<str>;
fn into_raw(shared: Self::Shared) -> *const str {
Rc::into_raw(shared)
}
unsafe fn increment_strong_count(ptr: *const str) {
unsafe {
Rc::increment_strong_count(ptr);
}
}
unsafe fn from_raw(ptr: *const str) -> Self::Shared {
unsafe { Rc::from_raw(ptr) }
}
fn from_str(s: &str) -> Self::Shared {
Rc::from(s)
}
fn from_string(s: String) -> Self::Shared {
Rc::from(s)
}
fn from_boxed_str(s: Box<str>) -> Self::Shared {
Rc::from(s)
}
}
pub enum SharedBackend {}
impl RefCountBackend for SharedBackend {
type Shared = Arc<str>;
fn into_raw(shared: Self::Shared) -> *const str {
Arc::into_raw(shared)
}
unsafe fn increment_strong_count(ptr: *const str) {
unsafe {
Arc::increment_strong_count(ptr);
}
}
unsafe fn from_raw(ptr: *const str) -> Self::Shared {
unsafe { Arc::from_raw(ptr) }
}
fn from_str(s: &str) -> Self::Shared {
Arc::from(s)
}
fn from_string(s: String) -> Self::Shared {
Arc::from(s)
}
fn from_boxed_str(s: Box<str>) -> Self::Shared {
Arc::from(s)
}
}