Trait Iden

Source
pub trait Iden {
    // Required method
    fn unquoted(&self) -> &str;

    // Provided methods
    fn quoted(&self) -> Cow<'static, str> { ... }
    fn to_string(&self) -> String { ... }
}
Expand description

Identifier

Required Methods§

Source

fn unquoted(&self) -> &str

Write a raw identifier string without quotes.

We intentionally don’t reuse Display for this, because we want to allow it to have a different logic.

Provided Methods§

Source

fn quoted(&self) -> Cow<'static, str>

Return the to-be sanitized version of the identifier.

For example, for MySQL “hello” would have to be escaped as “hel``lo”. Note that this method doesn’t do the actual escape, as it’s backend specific. It only indicates whether the identifier needs to be escaped.

If the identifier doesn’t need to be escaped, return 'static str. This can be deduced at compile-time by the Iden macro, or using the is_static_iden function.

Cow::Owned would always be escaped.

Source

fn to_string(&self) -> String

A shortcut for writing an unquoted identifier into a String.

We can’t reuse ToString for this, because ToString uses the Display representation. But Iden representation is distinct from Display and can be different.

Implementations on Foreign Types§

Source§

impl Iden for &'static str

Source§

fn quoted(&self) -> Cow<'static, str>

Source§

fn unquoted(&self) -> &str

Implementors§