use crate::{escape::escape_ident, strand::no_nul_bytes};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
use std::ops::Deref;
use std::str;
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[revisioned(revision = 1)]
pub struct Ident(#[serde(with = "no_nul_bytes")] pub String);
impl From<String> for Ident {
fn from(v: String) -> Self {
Self(v)
}
}
impl From<&str> for Ident {
fn from(v: &str) -> Self {
Self::from(String::from(v))
}
}
impl Deref for Ident {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Ident {
pub fn to_raw(&self) -> String {
self.0.to_string()
}
pub(crate) fn is_id(&self) -> bool {
self.0.as_str() == "id"
}
pub(crate) fn is_type(&self) -> bool {
self.0.as_str() == "type"
}
pub(crate) fn is_coordinates(&self) -> bool {
self.0.as_str() == "coordinates"
}
pub(crate) fn is_geometries(&self) -> bool {
self.0.as_str() == "geometries"
}
}
impl Display for Ident {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Display::fmt(&escape_ident(&self.0), f)
}
}