use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use std::ops::Deref;
pub(crate) const NAME_LIT_STR: &str = "__yaml_lit_str";
pub(crate) const NAME_FOLD_STR: &str = "__yaml_fold_str";
#[derive(Clone, Copy)]
pub struct LitStr<'a>(pub &'a str);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LitString(pub String);
#[derive(Clone, Copy)]
pub struct FoldStr<'a>(pub &'a str);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FoldString(pub String);
impl<'a> Serialize for LitStr<'a> {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
s.serialize_newtype_struct(NAME_LIT_STR, &self.0)
}
}
impl Serialize for LitString {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
s.serialize_newtype_struct(NAME_LIT_STR, &self.0)
}
}
impl<'a> Serialize for FoldStr<'a> {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
s.serialize_newtype_struct(NAME_FOLD_STR, &self.0)
}
}
impl Serialize for FoldString {
fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
s.serialize_newtype_struct(NAME_FOLD_STR, &self.0)
}
}
impl<'de> Deserialize<'de> for LitString {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
String::deserialize(deserializer).map(LitString)
}
}
impl<'de> Deserialize<'de> for FoldString {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> {
String::deserialize(deserializer).map(FoldString)
}
}
impl<'a> From<&'a str> for LitStr<'a> {
fn from(s: &'a str) -> Self {
LitStr(s)
}
}
impl<'a> From<&'a str> for FoldStr<'a> {
fn from(s: &'a str) -> Self {
FoldStr(s)
}
}
impl From<String> for LitString {
fn from(s: String) -> Self {
LitString(s)
}
}
impl From<String> for FoldString {
fn from(s: String) -> Self {
FoldString(s)
}
}
impl Deref for LitString {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Deref for FoldString {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> Deref for LitStr<'a> {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0
}
}
impl<'a> Deref for FoldStr<'a> {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0
}
}
impl LitString {
pub fn into_inner(self) -> String {
self.0
}
}
impl FoldString {
pub fn into_inner(self) -> String {
self.0
}
}
impl PartialEq<FoldString> for LitString {
fn eq(&self, other: &FoldString) -> bool {
self.0 == other.0
}
}
impl PartialEq<LitString> for FoldString {
fn eq(&self, other: &LitString) -> bool {
self.0 == other.0
}
}
impl PartialEq<String> for LitString {
fn eq(&self, other: &String) -> bool {
&self.0 == other
}
}
impl PartialEq<String> for FoldString {
fn eq(&self, other: &String) -> bool {
&self.0 == other
}
}
impl PartialEq<&str> for LitString {
fn eq(&self, other: &&str) -> bool {
self.0 == *other
}
}
impl PartialEq<&str> for FoldString {
fn eq(&self, other: &&str) -> bool {
self.0 == *other
}
}
impl PartialEq<str> for LitString {
fn eq(&self, other: &str) -> bool {
self.0 == other
}
}
impl PartialEq<str> for FoldString {
fn eq(&self, other: &str) -> bool {
self.0 == other
}
}