daml_lf/element/
daml_defvalue.rs

1use crate::element::daml_expr::DamlExpr;
2use crate::element::{DamlElementVisitor, DamlType, DamlVisitableElement};
3use bounded_static::ToStatic;
4use serde::Serialize;
5use std::borrow::Cow;
6
7/// A Daml value.
8#[derive(Debug, Serialize, Clone, ToStatic)]
9pub struct DamlDefValue<'a> {
10    pub name: Cow<'a, str>,
11    pub ty: DamlType<'a>,
12    pub expr: DamlExpr<'a>,
13    pub no_party_literals: bool,
14    pub is_test: bool,
15}
16
17impl<'a> DamlDefValue<'a> {
18    pub const fn new(
19        name: Cow<'a, str>,
20        ty: DamlType<'a>,
21        expr: DamlExpr<'a>,
22        no_party_literals: bool,
23        is_test: bool,
24    ) -> Self {
25        Self {
26            name,
27            ty,
28            expr,
29            no_party_literals,
30            is_test,
31        }
32    }
33
34    /// The name of this value.
35    pub fn name(&self) -> &str {
36        &self.name
37    }
38
39    /// The name of this value.
40    ///
41    /// This is a clone of a `Cow<str>` which is cheap for the borrowed case used within the library.
42    #[doc(hidden)]
43    pub fn name_clone(&self) -> Cow<'a, str> {
44        self.name.clone()
45    }
46
47    pub const fn ty(&self) -> &DamlType<'a> {
48        &self.ty
49    }
50
51    pub const fn expr(&self) -> &DamlExpr<'a> {
52        &self.expr
53    }
54
55    pub const fn no_party_literals(&self) -> bool {
56        self.no_party_literals
57    }
58
59    pub const fn is_test(&self) -> bool {
60        self.is_test
61    }
62}
63
64impl<'a> DamlVisitableElement<'a> for DamlDefValue<'a> {
65    fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
66        visitor.pre_visit_def_value(self);
67        self.ty.accept(visitor);
68        self.expr.accept(visitor);
69        visitor.post_visit_def_value(self);
70    }
71}