diff options
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 760a6499..59205efb 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1504,12 +1504,8 @@ impl Closure { } /// The parameter bindings. - pub fn params(&self) -> impl DoubleEndedIterator<Item = Param> + '_ { - self.0 - .children() - .find(|x| x.kind() == SyntaxKind::Params) - .map_or([].iter(), |params| params.children()) - .filter_map(SyntaxNode::cast) + pub fn params(&self) -> Params { + self.0.cast_first_match().unwrap_or_default() } /// The body of the closure. @@ -1518,6 +1514,18 @@ impl Closure { } } +node! { + /// A closure's parameters: `(x, y)`. + Params +} + +impl Params { + /// The parameter bindings. + pub fn children(&self) -> impl DoubleEndedIterator<Item = Param> + '_ { + self.0.children().filter_map(SyntaxNode::cast) + } +} + /// A parameter to a closure. #[derive(Debug, Clone, Hash)] pub enum Param { |
