Skip to main content

sql_fun_sqlast/sem/names/
local.rs

1use std::{fmt::Display, ops::Deref};
2
3/// part of name for schema specific local name
4#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
5#[serde(transparent)]
6pub struct LocalName(String);
7
8impl LocalName {
9    /// create from string
10    #[must_use]
11    pub fn from(value: &str) -> Self {
12        Self(value.to_string())
13    }
14    /// convert to string
15    #[must_use]
16    pub fn as_str(&self) -> &str {
17        &self.0
18    }
19
20    /// local name is record
21    #[must_use]
22    pub fn is_record(&self) -> bool {
23        &self.0 == "record"
24    }
25}
26
27impl Display for LocalName {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(f, "{}", self.0)
30    }
31}
32
33impl Deref for LocalName {
34    type Target = str;
35
36    fn deref(&self) -> &Self::Target {
37        self.0.as_ref()
38    }
39}