aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index efe261fc2..8de979ca2 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -399,3 +399,29 @@ impl ast::TraitDef {
399 self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) 399 self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
400 } 400 }
401} 401}
402
403#[derive(Clone, Debug, PartialEq, Eq, Hash)]
404pub enum TypeBoundKind {
405 /// Trait
406 PathType(ast::PathType),
407 /// for<'a> ...
408 ForType(ast::ForType),
409 /// 'a
410 Lifetime(ast::SyntaxToken),
411}
412
413impl ast::TypeBound {
414 pub fn kind(&self) -> Option<TypeBoundKind> {
415 let child = self.syntax.first_child_or_token()?;
416 match child.kind() {
417 PATH_TYPE => Some(TypeBoundKind::PathType(
418 ast::PathType::cast(child.into_node().unwrap()).unwrap(),
419 )),
420 FOR_TYPE => Some(TypeBoundKind::ForType(
421 ast::ForType::cast(child.into_node().unwrap()).unwrap(),
422 )),
423 LIFETIME => Some(TypeBoundKind::Lifetime(child.into_token().unwrap())),
424 _ => unreachable!(),
425 }
426 }
427}