pub trait MaybeLiteral {
// Required method
fn extend_literal<T: Extend<char>>(
&self,
result: &mut T,
) -> Result<(), NotLiteral>;
// Provided method
fn to_string_if_literal(&self) -> Option<String> { ... }
}
Expand description
Possibly literal syntax element
A syntax element is literal if it is not quoted and does not contain any expansions. Such an element may be considered as a constant string, and is a candidate for a keyword or identifier.
let text = Text(vec![Literal('f'), Literal('o'), Literal('o')]);
let expanded = text.to_string_if_literal().unwrap();
assert_eq!(expanded, "foo");
let backslashed = Text(vec![Backslashed('a')]);
assert_eq!(backslashed.to_string_if_literal(), None);
Required Methods§
Sourcefn extend_literal<T: Extend<char>>(
&self,
result: &mut T,
) -> Result<(), NotLiteral>
fn extend_literal<T: Extend<char>>( &self, result: &mut T, ) -> Result<(), NotLiteral>
Appends the literal representation of self
to an extendable object.
If self
is literal, the literal representation is appended to result
and Ok(())
is returned. Otherwise, Err(NotLiteral)
is returned and
result
may contain some characters that have been appended.
Provided Methods§
Sourcefn to_string_if_literal(&self) -> Option<String>
fn to_string_if_literal(&self) -> Option<String>
Checks if self
is literal and, if so, converts to a string.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.