use std::borrow::Cow;
use std::ops::Deref;
use serde::Deserialize;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize)]
pub struct CowStr<'a>(#[serde(borrow)] pub Cow<'a, str>);
impl Deref for CowStr<'_> {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl PartialEq<&str> for CowStr<'_> {
fn eq(&self, other: &&str) -> bool {
self.0 == *other
}
}
impl<'a> From<&'a str> for CowStr<'a> {
fn from(s: &'a str) -> Self {
Self(Cow::Borrowed(s))
}
}
impl<'a> From<CowStr<'a>> for Cow<'a, str> {
fn from(s: CowStr<'a>) -> Self {
s.0
}
}