Skip to main content

wright/ast/decl/
record.rs

1//! Record declarations, such as `record Point { x: i32, y: i32 }`.
2
3use super::Visibility;
4use crate::ast::{AstNode, identifier::Identifier, ty::Type};
5use crate::source_tracking::fragment::Fragment;
6
7/// A record (struct) declaration.
8#[derive(Debug, Clone, PartialEq)]
9pub struct RecordDecl {
10    /// Full matching source of the declaration.
11    pub matching_source: Fragment,
12
13    /// The name of the record.
14    pub name: Identifier,
15
16    /// Generic type parameters, such as the `T` in `record Wrapper<T> { inner: T }`.
17    pub generics: Vec<Identifier>,
18
19    /// The fields of the record, in order.
20    pub fields: Vec<RecordField>,
21}
22
23/// A field of a [RecordDecl], such as `pub x: i32`.
24#[derive(Debug, Clone, PartialEq)]
25pub struct RecordField {
26    /// Full matching source of the field.
27    pub matching_source: Fragment,
28
29    /// The visibility of the field.
30    pub visibility: Visibility,
31
32    /// The name of the field.
33    pub name: Identifier,
34
35    /// The type of the field.
36    pub ty: Type,
37}
38
39impl AstNode for RecordField {
40    fn matching_source(&self) -> &Fragment {
41        &self.matching_source
42    }
43}