Skip to main content

sql_fun_sqlast/sem/create_table/
column_name.rs

1use std::fmt::Display;
2
3/// column name
4#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
5pub struct ColumnName(String);
6
7impl ColumnName {
8    /// create from string
9    #[must_use]
10    pub fn new(name: &str) -> Self {
11        Self(String::from(name))
12    }
13
14    /// get as &str
15    #[must_use]
16    pub fn as_str(&self) -> &str {
17        self.0.as_str()
18    }
19}
20
21impl From<String> for ColumnName {
22    fn from(value: String) -> Self {
23        Self(value)
24    }
25}
26
27impl From<&str> for ColumnName {
28    fn from(value: &str) -> Self {
29        Self(String::from(value))
30    }
31}
32
33impl Display for ColumnName {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        write!(f, "{}", self.0)
36    }
37}