2024-04-16 08:05:07 +00:00
|
|
|
use crate::sql::statements::info::InfoStructure;
|
|
|
|
use crate::sql::{escape::escape_ident, strand::no_nul_bytes, Value};
|
2023-08-17 18:03:46 +00:00
|
|
|
use revision::revisioned;
|
2020-06-29 15:36:01 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-10-04 21:51:18 +00:00
|
|
|
use std::fmt::{self, Display, Formatter};
|
2022-05-05 00:27:57 +00:00
|
|
|
use std::ops::Deref;
|
2020-06-29 15:36:01 +00:00
|
|
|
use std::str;
|
|
|
|
|
2023-08-17 18:03:46 +00:00
|
|
|
#[revisioned(revision = 1)]
|
2024-04-17 14:27:55 +00:00
|
|
|
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
2024-01-09 15:34:52 +00:00
|
|
|
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
2024-04-02 20:12:08 +00:00
|
|
|
#[non_exhaustive]
|
2023-05-09 17:48:14 +00:00
|
|
|
pub struct Ident(#[serde(with = "no_nul_bytes")] pub String);
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2021-05-24 08:18:58 +00:00
|
|
|
impl From<String> for Ident {
|
2023-03-31 15:42:29 +00:00
|
|
|
fn from(v: String) -> Self {
|
|
|
|
Self(v)
|
2021-05-24 08:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-25 09:42:10 +00:00
|
|
|
impl From<&str> for Ident {
|
2023-03-31 15:42:29 +00:00
|
|
|
fn from(v: &str) -> Self {
|
|
|
|
Self::from(String::from(v))
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 00:27:57 +00:00
|
|
|
impl Deref for Ident {
|
|
|
|
type Target = String;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
2022-04-07 10:12:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 19:44:27 +00:00
|
|
|
impl Ident {
|
2022-10-19 09:55:19 +00:00
|
|
|
/// Convert the Ident to a raw String
|
2022-05-31 19:44:27 +00:00
|
|
|
pub fn to_raw(&self) -> String {
|
|
|
|
self.0.to_string()
|
|
|
|
}
|
2023-07-01 21:04:24 +00:00
|
|
|
/// Checks if this field is the `id` field
|
2022-10-19 10:03:13 +00:00
|
|
|
pub(crate) fn is_id(&self) -> bool {
|
|
|
|
self.0.as_str() == "id"
|
|
|
|
}
|
2023-07-01 21:04:24 +00:00
|
|
|
/// Checks if this field is the `type` field
|
|
|
|
pub(crate) fn is_type(&self) -> bool {
|
|
|
|
self.0.as_str() == "type"
|
|
|
|
}
|
|
|
|
/// Checks if this field is the `coordinates` field
|
|
|
|
pub(crate) fn is_coordinates(&self) -> bool {
|
|
|
|
self.0.as_str() == "coordinates"
|
|
|
|
}
|
|
|
|
/// Checks if this field is the `geometries` field
|
|
|
|
pub(crate) fn is_geometries(&self) -> bool {
|
|
|
|
self.0.as_str() == "geometries"
|
|
|
|
}
|
2022-05-31 19:44:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 21:51:18 +00:00
|
|
|
impl Display for Ident {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
|
|
|
Display::fmt(&escape_ident(&self.0), f)
|
2020-06-29 15:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-16 08:05:07 +00:00
|
|
|
|
|
|
|
impl InfoStructure for Ident {
|
|
|
|
fn structure(self) -> Value {
|
|
|
|
self.0.into()
|
|
|
|
}
|
|
|
|
}
|