Trait yash_syntax::syntax::MaybeLiteral
source · [−]pub trait MaybeLiteral {
fn extend_if_literal<T: Extend<char>>(&self, result: T) -> Result<T, T>;
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 can be expanded to a string independently of the shell execution environment.
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
fn extend_if_literal<T: Extend<char>>(&self, result: T) -> Result<T, T>
fn extend_if_literal<T: Extend<char>>(&self, result: T) -> Result<T, T>
Checks if self is literal and, if so, converts to a string and appends
it to result.
If self is literal, self converted to a string is appended to
result and Ok(result) is returned. Otherwise, result is not
modified and Err(result) is returned.
Provided Methods
fn 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.