oq3_syntax/ast/
traits.rs

1// Copyright contributors to the openqasm-parser project
2// SPDX-License-Identifier: Apache-2.0
3
4//! Various traits that are implemented by ast nodes.
5//!
6//! The implementations are usually trivial, and live in generated.rs
7//!
8//! NOTE!!! This is not support for the rust traits!
9//! This cannot be removed for OQ3.
10
11use either::Either;
12
13use crate::ast::{self, support, AstNode};
14
15pub trait HasName: AstNode {
16    fn name(&self) -> Option<ast::Name> {
17        support::child(self.syntax())
18    }
19}
20
21pub trait HasLoopBody: AstNode {
22    fn loop_body(&self) -> Option<ast::BlockExpr> {
23        support::child(self.syntax())
24    }
25}
26
27pub trait HasArgList: AstNode {
28    fn arg_list(&self) -> Option<ast::ArgList> {
29        support::child(self.syntax())
30    }
31}
32
33impl<A: HasName, B: HasName> HasName for Either<A, B> {}