daml_lf/element/
daml_field.rs

1use crate::element::daml_type::DamlType;
2use crate::element::visitor::DamlElementVisitor;
3use crate::element::DamlVisitableElement;
4use bounded_static::ToStatic;
5use serde::Serialize;
6use std::borrow::Cow;
7
8/// A Daml field.
9#[derive(Debug, Serialize, Clone, ToStatic)]
10pub struct DamlField<'a> {
11    name: Cow<'a, str>,
12    ty: DamlType<'a>,
13}
14
15impl<'a> DamlField<'a> {
16    pub const fn new(name: Cow<'a, str>, ty: DamlType<'a>) -> Self {
17        Self {
18            name,
19            ty,
20        }
21    }
22
23    pub fn name(&self) -> &str {
24        &self.name
25    }
26
27    pub const fn ty(&self) -> &DamlType<'a> {
28        &self.ty
29    }
30}
31
32impl<'a> DamlVisitableElement<'a> for DamlField<'a> {
33    fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
34        visitor.pre_visit_field(self);
35        self.ty.accept(visitor);
36        visitor.post_visit_field(self);
37    }
38}