use alloc::borrow::Cow;
use alloc::string::String;
use core::fmt;
use facet::Facet;
#[derive(Clone, PartialEq, Eq, Hash, Facet)]
pub struct RawJson<'a>(pub Cow<'a, str>);
impl<'a> RawJson<'a> {
#[inline]
pub const fn new(s: &'a str) -> Self {
RawJson(Cow::Borrowed(s))
}
#[inline]
pub const fn from_owned(s: String) -> Self {
RawJson(Cow::Owned(s))
}
#[inline]
pub fn as_str(&self) -> &str {
&self.0
}
#[inline]
pub fn into_owned(self) -> RawJson<'static> {
RawJson(Cow::Owned(self.0.into_owned()))
}
}
impl fmt::Debug for RawJson<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("RawJson").field(&self.0).finish()
}
}
impl fmt::Display for RawJson<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl<'a> From<&'a str> for RawJson<'a> {
fn from(s: &'a str) -> Self {
RawJson::new(s)
}
}
impl<'a> From<Cow<'a, str>> for RawJson<'a> {
fn from(s: Cow<'a, str>) -> Self {
RawJson(s)
}
}
impl From<String> for RawJson<'static> {
fn from(s: String) -> Self {
RawJson::from_owned(s)
}
}
impl<'a> AsRef<str> for RawJson<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}