Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/node_ext.rs')
-rw-r--r--crates/syntax/src/ast/node_ext.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 691d0c618f..457c3c1996 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -361,6 +361,18 @@ impl ast::Impl {
}
}
+// for `PathSegment` '<i32 as core::ops::Add>', call `first_path_type` will get `i32` and `last_path_type` will get `core::ops::Add`
+// for '<&i32 as core::ops::Add>', call `first_path_type` and `last_path_type` will both get `core::ops::Add` cause `&i32` is `Type(RefType)`
+impl ast::PathSegment {
+ pub fn first_path_type(&self) -> Option<ast::PathType> {
+ self.syntax().children().find_map(ast::PathType::cast)
+ }
+
+ pub fn last_path_type(&self) -> Option<ast::PathType> {
+ self.syntax().children().filter_map(ast::PathType::cast).last()
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StructKind {
Record(ast::RecordFieldList),