1 use syn::{
2 ext::IdentExt,
3 parse::{ParseStream, Result},
4 punctuated::Punctuated,
5 Ident, Path, PathArguments, PathSegment, Token,
6 };
7
parse_path_segment(input: ParseStream<'_>) -> Result<PathSegment>8 fn parse_path_segment(input: ParseStream<'_>) -> Result<PathSegment> {
9 if input.peek(Token![super]) || input.peek(Token![self]) || input.peek(Token![crate]) {
10 let ident = input.call(Ident::parse_any)?;
11 return Ok(PathSegment::from(ident));
12 }
13
14 let ident =
15 if input.peek(Token![Self]) { input.call(Ident::parse_any)? } else { input.parse()? };
16
17 if input.peek(Token![::]) && input.peek3(Token![<]) {
18 Ok(PathSegment { ident, arguments: PathArguments::AngleBracketed(input.parse()?) })
19 } else {
20 Ok(PathSegment::from(ident))
21 }
22 }
23
parse_path(input: ParseStream<'_>) -> Result<Path>24 pub(crate) fn parse_path(input: ParseStream<'_>) -> Result<Path> {
25 Ok(Path {
26 leading_colon: input.parse()?,
27 segments: {
28 let mut segments = Punctuated::new();
29 let value = parse_path_segment(input)?;
30 segments.push_value(value);
31 while input.peek(Token![::]) {
32 let punct: Token![::] = input.parse()?;
33 segments.push_punct(punct);
34 let value = parse_path_segment(input)?;
35 segments.push_value(value);
36 }
37 segments
38 },
39 })
40 }
41