diff options
author | David Tolnay <dtolnay@gmail.com> | 2023-03-15 22:23:11 -0700 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2023-03-15 22:23:11 -0700 |
commit | 50d9d69ef5269d9bdb14e8e3f1e57b292a770f7b (patch) | |
tree | 024ba6e4c3e99b77de00d96a21da8a11c41f2329 | |
parent | 8f822ad8b7dc49fad161bbe1fee1afa0b85ab6f4 (diff) | |
download | cxx-50d9d69ef5269d9bdb14e8e3f1e57b292a770f7b.tar.gz |
Factor out a constructor from LitStr to QualifiedName
-rw-r--r-- | syntax/qualified.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/syntax/qualified.rs b/syntax/qualified.rs index 5f182fa9..e11ffbc1 100644 --- a/syntax/qualified.rs +++ b/syntax/qualified.rs @@ -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) } |