Factor out a constructor from LitStr to QualifiedName

This commit is contained in:
David Tolnay 2023-03-15 22:23:11 -07:00
parent 8f822ad8b7
commit 50d9d69ef5
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -7,14 +7,7 @@ pub struct QualifiedName {
} }
impl QualifiedName { impl QualifiedName {
pub fn parse_unquoted(input: ParseStream) -> Result<Self> { pub fn parse_quoted(lit: &LitStr) -> Result<Self> {
let allow_raw = true;
parse_unquoted(input, allow_raw)
}
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
if input.peek(LitStr) {
let lit: LitStr = input.parse()?;
if lit.value().is_empty() { if lit.value().is_empty() {
let segments = Vec::new(); let segments = Vec::new();
Ok(QualifiedName { segments }) Ok(QualifiedName { segments })
@ -24,6 +17,17 @@ impl QualifiedName {
parse_unquoted(input, allow_raw) parse_unquoted(input, allow_raw)
}) })
} }
}
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
let allow_raw = true;
parse_unquoted(input, allow_raw)
}
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
if input.peek(LitStr) {
let lit: LitStr = input.parse()?;
Self::parse_quoted(&lit)
} else { } else {
Self::parse_unquoted(input) Self::parse_unquoted(input)
} }