use std::ops::Deref;
use compact_str::{CompactString, ToCompactString};
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct Str(CompactString);
impl Str {
pub const fn new(str: &'static str) -> Self {
Self(CompactString::const_new(str))
}
pub fn into_inner(self) -> CompactString {
self.0
}
}
impl AsRef<str> for Str {
fn as_ref(&self) -> &str {
self.0.as_str()
}
}
impl Deref for Str {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0.as_str()
}
}
impl From<&Str> for Str {
fn from(value: &Str) -> Self {
value.clone()
}
}
impl<T> From<T> for Str
where
T: ToCompactString,
{
fn from(value: T) -> Self {
Self(value.to_compact_string())
}
}
#[macro_export]
macro_rules! format_str {
($($arg:tt)*) => {
$crate::Str::from($crate::__dont_use_this_because_semver!($($arg)*))
}
}