Skip to content

Commit 50d9d69

Browse files
committed
Factor out a constructor from LitStr to QualifiedName
1 parent 8f822ad commit 50d9d69

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

syntax/qualified.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ pub struct QualifiedName {
77
}
88

99
impl QualifiedName {
10+
pub fn parse_quoted(lit: &LitStr) -> Result<Self> {
11+
if lit.value().is_empty() {
12+
let segments = Vec::new();
13+
Ok(QualifiedName { segments })
14+
} else {
15+
lit.parse_with(|input: ParseStream| {
16+
let allow_raw = false;
17+
parse_unquoted(input, allow_raw)
18+
})
19+
}
20+
}
21+
1022
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
1123
let allow_raw = true;
1224
parse_unquoted(input, allow_raw)
@@ -15,15 +27,7 @@ impl QualifiedName {
1527
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
1628
if input.peek(LitStr) {
1729
let lit: LitStr = input.parse()?;
18-
if lit.value().is_empty() {
19-
let segments = Vec::new();
20-
Ok(QualifiedName { segments })
21-
} else {
22-
lit.parse_with(|input: ParseStream| {
23-
let allow_raw = false;
24-
parse_unquoted(input, allow_raw)
25-
})
26-
}
30+
Self::parse_quoted(&lit)
2731
} else {
2832
Self::parse_unquoted(input)
2933
}

0 commit comments

Comments
 (0)