diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-19 17:08:17 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-19 17:08:17 +0100 |
commit | f697d27c31ba4486b9711893a93505a05319a2dc (patch) | |
tree | 9c7996d6ac7323da527fb53171b9275545d1640a /crates/ra_syntax/src/syntax_node.rs | |
parent | 7bc9dec7cf195bc73a88d7c740f9d0bed1019e98 (diff) | |
parent | 191a6ba330bd47fc3b9cc05d59b2d456b471eb89 (diff) |
Merge #1554
1554: convenience api r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/syntax_node.rs')
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index cf680e66a..98955832b 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs | |||
@@ -423,6 +423,13 @@ impl SyntaxElement { | |||
423 | } | 423 | } |
424 | } | 424 | } |
425 | 425 | ||
426 | pub fn into_node(self) -> Option<SyntaxNode> { | ||
427 | match self { | ||
428 | SyntaxElement::Node(node) => Some(node), | ||
429 | SyntaxElement::Token(_) => None, | ||
430 | } | ||
431 | } | ||
432 | |||
426 | pub fn as_token(&self) -> Option<&SyntaxToken> { | 433 | pub fn as_token(&self) -> Option<&SyntaxToken> { |
427 | match self { | 434 | match self { |
428 | SyntaxElement::Node(_) => None, | 435 | SyntaxElement::Node(_) => None, |
@@ -430,6 +437,13 @@ impl SyntaxElement { | |||
430 | } | 437 | } |
431 | } | 438 | } |
432 | 439 | ||
440 | pub fn into_token(self) -> Option<SyntaxToken> { | ||
441 | match self { | ||
442 | SyntaxElement::Node(_) => None, | ||
443 | SyntaxElement::Token(token) => Some(token), | ||
444 | } | ||
445 | } | ||
446 | |||
433 | pub fn next_sibling_or_token(&self) -> Option<SyntaxElement> { | 447 | pub fn next_sibling_or_token(&self) -> Option<SyntaxElement> { |
434 | match self { | 448 | match self { |
435 | SyntaxElement::Node(it) => it.next_sibling_or_token(), | 449 | SyntaxElement::Node(it) => it.next_sibling_or_token(), |