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,6 +7,18 @@ pub struct QualifiedName {
}
impl QualifiedName {
pub fn parse_quoted(lit: &LitStr) -> Result<Self> {
if lit.value().is_empty() {
let segments = Vec::new();
Ok(QualifiedName { segments })
} else {
lit.parse_with(|input: ParseStream| {
let allow_raw = false;
parse_unquoted(input, allow_raw)
})
}
}
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
let allow_raw = true;
parse_unquoted(input, allow_raw)
@ -15,15 +27,7 @@ impl QualifiedName {
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
if input.peek(LitStr) {
let lit: LitStr = input.parse()?;
if lit.value().is_empty() {
let segments = Vec::new();
Ok(QualifiedName { segments })
} else {
lit.parse_with(|input: ParseStream| {
let allow_raw = false;
parse_unquoted(input, allow_raw)
})
}
Self::parse_quoted(&lit)
} else {
Self::parse_unquoted(input)
}