pub struct Ident(/* private fields */);Expand description
An identifier.
Implementationsยง
Sourceยงimpl Ident
impl Ident
Sourcepub const MAX_LENGTH: usize = MAX_IDENTIFIER_LENGTH
pub const MAX_LENGTH: usize = MAX_IDENTIFIER_LENGTH
Maximum length of an identifier in Materialize.
Sourcepub fn new<S>(s: S) -> Result<Self, IdentError>
pub fn new<S>(s: S) -> Result<Self, IdentError>
Create a new Ident with the given value, checking our invariants.
ยงExamples
use mz_sql_parser::ast::Ident;
let id = Ident::new("hello_world").unwrap();
assert_eq!(id.as_str(), "hello_world");
let too_long = "I am a very long identifier that is more than 255 bytes long which is the max length for idents.\
๐๐๐
๐๐ฌ๐ป๐ฎโ๐จ๐ฎ๐ฝ๐ฐ๏ธ๐๐๐๐
๐๐ฌ๐ป๐ฎโ๐จ๐ฎ๐ฝ๐ฐ๏ธ๐๐๐๐
๐๐ฌ๐ป๐ฎโ๐จ๐ฎ๐ฝ๐ฐ๏ธ๐";
assert_eq!(too_long.len(), 258);
let too_long_id = Ident::new(too_long);
assert!(too_long_id.is_err());
let invalid_name_dot = Ident::new(".");
assert!(invalid_name_dot.is_err());
let invalid_name_dot_dot = Ident::new("..");
assert!(invalid_name_dot_dot.is_err());Sourcepub fn new_lossy<S: Into<String>>(value: S) -> Self
pub fn new_lossy<S: Into<String>>(value: S) -> Self
Create a new Ident modifying the given value as necessary to meet our invariants.
ยงExamples
use mz_sql_parser::ast::Ident;
let too_long = "๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต\
๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด";
let id = Ident::new_lossy(too_long);
// `new_lossy` will truncate the provided string, since it's too long. Note the missing
// `๐ด` characters.
assert_eq!(id.as_str(), "๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต");Sourcepub fn new_unchecked<S: Into<String>>(value: S) -> Self
pub fn new_unchecked<S: Into<String>>(value: S) -> Self
Create a new Ident without checking any of our invariants.
NOTE: Generally you should not use this function! If youโre trying to create an
Ident from a &'static str you know is valid, use the ident! macro. For all other
use cases, see Ident::new which correctly checks our invariants.
Sourcepub fn try_generate_name<P, S, F, E>(
prefix: P,
suffix: S,
is_valid: F,
) -> Result<Self, E>
pub fn try_generate_name<P, S, F, E>( prefix: P, suffix: S, is_valid: F, ) -> Result<Self, E>
Generate a valid Ident with the provided prefix and suffix.
ยงExamples
use mz_sql_parser::ast::{Ident, IdentError};
let good_id =
Ident::try_generate_name("hello", "_world", |_| Ok::<_, IdentError>(true)).unwrap();
assert_eq!(good_id.as_str(), "hello_world");
// Return invalid once.
let mut attempts = 0;
let one_failure = Ident::try_generate_name("hello", "_world", |_candidate| {
if attempts == 0 {
attempts += 1;
Ok::<_, IdentError>(false)
} else {
Ok(true)
}
})
.unwrap();
// We "hello_world" was invalid, so we appended "_1".
assert_eq!(one_failure.as_str(), "hello_world_1");Sourcepub fn append_lossy<S: Into<String>>(&mut self, suffix: S)
pub fn append_lossy<S: Into<String>>(&mut self, suffix: S)
Append the provided suffix, truncating self as necessary to satisfy our invariants.
Note: We soft-assert that the provided suffix is not too long, if it is, weโll
truncate it.
ยงExamples
use mz_sql_parser::{
ident,
ast::Ident,
};
let mut id = ident!("๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต๐ต");
id.append_lossy("๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด");
// We truncated the original ident, removing all '๐ต' chars.
assert_eq!(id.as_str(), "๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด๐ด");ยงToo long suffix
If the provided suffix is too long, weโll also truncate that.
use mz_sql_parser::{
ident,
ast::Ident,
};
let mut stem = ident!("hello___world");
let too_long_suffix = "\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ต๐ต\
";
stem.append_lossy(too_long_suffix);
// Notice the "hello___world" stem got truncated, as did the "๐ต๐ต" characters from the suffix.
let result = "hello___wor\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข๐ข\
";
assert_eq!(stem.as_str(), result);Sourcepub fn has_only_bare_chars(&self) -> bool
pub fn has_only_bare_chars(&self) -> bool
Reports whether the identifier matches the regex [a-z_][a-z0-9_]*,
i.e. it is composed only of characters that never require quoting.
This is the character-level half of Ident::can_be_printed_bare. It
deliberately does not consider keywords: whether a keyword-named
identifier needs quoting depends on the surrounding grammar (a
reparsing concern), not on its characters. Contexts that only need
legible, unambiguous output โ rather than a SQL round-trip โ should use
this instead (see HumanizedExplain::humanize_ident).
Sourcepub fn can_be_printed_bare(&self) -> bool
pub fn can_be_printed_bare(&self) -> bool
An identifier can be printed in bare mode if
- it matches the regex
[a-z_][a-z0-9_]*and - it is not a โreserved keyword.โ
pub fn as_str(&self) -> &str
pub fn as_keyword(&self) -> Option<Keyword>
pub fn into_string(self) -> String
Trait Implementationsยง
Sourceยงimpl AstDisplay for Ident
More-or-less a direct translation of the Postgres function for doing the same thing:
impl AstDisplay for Ident
More-or-less a direct translation of the Postgres function for doing the same thing:
https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/ruleutils.c#L10730-L10812
Quotation is forced when printing in Stable mode.
fn fmt<W: Write>(&self, f: &mut AstFormatter<W>)
fn to_ast_string_simple(&self) -> String
fn to_ast_string_stable(&self) -> String
fn to_ast_string_redacted(&self) -> String
fn to_ast_string(&self, format_mode: FormatMode) -> String
Sourceยงimpl<'de> Deserialize<'de> for Ident
impl<'de> Deserialize<'de> for Ident
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Sourceยงimpl Ord for Ident
impl Ord for Ident
1.21.0 (const: unstable) ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl PartialOrd for Ident
impl PartialOrd for Ident
Sourceยงimpl<'ast, T: AstInfo> VisitMutNode<'ast, T> for Ident
impl<'ast, T: AstInfo> VisitMutNode<'ast, T> for Ident
impl Eq for Ident
impl StructuralPartialEq for Ident
Auto Trait Implementationsยง
impl Freeze for Ident
impl RefUnwindSafe for Ident
impl Send for Ident
impl Sync for Ident
impl Unpin for Ident
impl UnsafeUnpin for Ident
impl UnwindSafe for Ident
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Sourceยงimpl<T> FutureExt for T
impl<T> FutureExt for T
Sourceยงfn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Sourceยงfn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Sourceยงfn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSourceยงimpl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Sourceยงfn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
ยงExample
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Sourceยงfn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Sourceยงfn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Sourceยงfn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Sourceยงfn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Sourceยงfn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Sourceยงfn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Sourceยงfn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Sourceยงfn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Sourceยงfn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
ยงExample
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Sourceยงfn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Sourceยงfn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Sourceยงfn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Sourceยงfn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Sourceยงfn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Sourceยงfn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Sourceยงfn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Sourceยงfn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Sourceยงfn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Sourceยงfn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
ยงExample
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Sourceยงfn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Sourceยงfn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
ยงExample
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Sourceยงfn clear(&self) -> Painted<&T>
๐Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Sourceยงfn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
ยงExample
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Sourceยงimpl<T> Pointable for T
impl<T> Pointable for T
Sourceยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Sourceยงimpl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
Sourceยงfn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign, for types that do not implement AddAssign.