use std::{
borrow::Cow,
fmt::{Debug, Formatter},
};
#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
use bounded_static_derive::ToStatic;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::core::{Literal, LiteralMode};
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, ToStatic)]
pub enum LiteralOrLiteral8<'a> {
Literal(Literal<'a>),
Literal8(Literal8<'a>),
}
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Hash, ToStatic)]
pub struct Literal8<'a> {
pub data: Cow<'a, [u8]>,
pub mode: LiteralMode,
}
impl<'a> Debug for Literal8<'a> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
struct BStr<'a>(&'a Cow<'a, [u8]>);
impl<'a> Debug for BStr<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"b\"{}\"",
crate::utils::escape_byte_string(self.0.as_ref())
)
}
}
f.debug_struct("Literal8")
.field("data", &BStr(&self.data))
.field("mode", &self.mode)
.finish()
}
}