use alloc::borrow::Cow;
use core::{
fmt,
hash::{Hash, Hasher},
};
#[derive(Debug, Clone)]
pub struct PgBpchar<'a>(Cow<'a, str>);
impl<'a> PgBpchar<'a> {
pub fn new(text: impl Into<Cow<'a, str>>) -> Self {
Self(text.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn as_text(&self) -> &str {
self.0.trim_end_matches(' ')
}
}
impl PartialEq<PgBpchar<'_>> for PgBpchar<'_> {
fn eq(&self, other: &PgBpchar<'_>) -> bool {
self.as_text() == other.as_text()
}
}
impl Eq for PgBpchar<'_> {}
impl Hash for PgBpchar<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.as_text().hash(state);
}
}
impl fmt::Display for PgBpchar<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}