toasty_sql/stmt/
name.rs

1use std::fmt;
2
3/// A possibly schema-qualified SQL name (e.g. `"users"` or `"public"."users"`).
4///
5/// Stores each segment as a separate string. Single-segment names are the
6/// common case.
7///
8/// # Example
9///
10/// ```
11/// use toasty_sql::stmt::Name;
12///
13/// let name = Name::from("users");
14/// assert_eq!(name.to_string(), "users");
15/// ```
16#[derive(Debug, Clone)]
17pub struct Name(pub Vec<String>);
18
19impl From<&str> for Name {
20    fn from(value: &str) -> Self {
21        Self(vec![value.into()])
22    }
23}
24
25impl From<&String> for Name {
26    fn from(value: &String) -> Self {
27        Self::from(&value[..])
28    }
29}
30
31impl fmt::Display for Name {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        let mut s = "";
34        for ident in &self.0 {
35            write!(f, "{s}{ident}")?;
36            s = ", ";
37        }
38
39        Ok(())
40    }
41}