-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathpath.rs
More file actions
29 lines (24 loc) · 748 Bytes
/
path.rs
File metadata and controls
29 lines (24 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::util::prelude::*;
pub(crate) trait PathExt {
fn starts_with_segment(&self, desired_segment: &str) -> bool;
/// Returns an error if this path has some generic arguments.
fn require_mod_style(&self) -> Result;
}
impl PathExt for syn::Path {
fn starts_with_segment(&self, desired_segment: &str) -> bool {
self.segments
.first()
.map(|first| first.ident == desired_segment)
.unwrap_or(false)
}
fn require_mod_style(&self) -> Result {
if self
.segments
.iter()
.any(|seg| seg.arguments != syn::PathArguments::None)
{
bail!(self, "expected a simple path e.g. `foo::bar`");
}
Ok(())
}
}