use iron_shapes::point::Deref;
use std::borrow::Borrow;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RcString {
string: Arc<String>,
}
impl std::fmt::Display for RcString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.string.as_str(), f)
}
}
impl RcString {
pub fn new(string: String) -> Self {
RcString {
string: Arc::new(string),
}
}
}
impl Hash for RcString {
fn hash<H: Hasher>(&self, state: &mut H) {
self.string.hash(state)
}
}
impl Deref for RcString {
type Target = String;
fn deref(&self) -> &Self::Target {
self.string.deref()
}
}
impl Borrow<str> for RcString {
fn borrow(&self) -> &str {
self.as_str()
}
}
impl Borrow<String> for RcString {
fn borrow(&self) -> &String {
self.string.deref()
}
}
impl From<String> for RcString {
fn from(string: String) -> Self {
Self::new(string)
}
}
impl From<Arc<String>> for RcString {
fn from(string: Arc<String>) -> Self {
Self { string }
}
}
impl From<&Arc<String>> for RcString {
fn from(string: &Arc<String>) -> Self {
Self {
string: string.clone(),
}
}
}
impl From<&str> for RcString {
fn from(s: &str) -> Self {
Self::new(s.to_string())
}
}
impl From<RcString> for String {
fn from(val: RcString) -> Self {
val.string.to_string()
}
}