#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DamlType {
Unit,
Bool,
Int64,
Numeric(u8),
Text,
Timestamp,
Date,
Party,
ContractId(Box<DamlType>),
List(Box<DamlType>),
Optional(Box<DamlType>),
TextMap(Box<DamlType>),
GenMap(Box<DamlType>, Box<DamlType>),
Ref(TypeRef),
Var(String),
Boxed(Box<DamlType>),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct TypeRef {
pub path: Vec<String>,
pub args: Vec<DamlType>,
}
impl TypeRef {
#[must_use]
pub fn local(name: impl Into<String>, args: Vec<DamlType>) -> Self {
Self {
path: vec![name.into()],
args,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Field {
pub label: String,
pub ty: DamlType,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Record {
pub name: String,
pub type_params: Vec<String>,
pub fields: Vec<Field>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DataType {
Record(Record),
Variant(Variant),
Enum(Enum),
InterfaceMarker(String),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Variant {
pub name: String,
pub type_params: Vec<String>,
pub constructors: Vec<VariantConstructor>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct VariantConstructor {
pub name: String,
pub payload: Option<DamlType>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Enum {
pub name: String,
pub constructors: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Template {
pub name: String,
pub module_name: String,
pub package_id: String,
pub package_name: String,
pub fields: Vec<Field>,
pub choices: Vec<Choice>,
pub key: Option<DamlType>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Choice {
pub name: String,
pub consuming: bool,
pub argument: DamlType,
pub returns: DamlType,
}
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct Module {
pub data_types: Vec<DataType>,
pub templates: Vec<Template>,
pub interfaces: Vec<Interface>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Interface {
pub name: String,
pub module_name: String,
pub package_id: String,
pub package_name: String,
pub view: Option<DamlType>,
pub choices: Vec<Choice>,
}
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct Crate {
pub packages: Vec<PackageModule>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PackageModule {
pub name: String,
pub modules: Vec<NamedModule>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct NamedModule {
pub name: String,
pub module: Module,
}
impl TypeRef {
#[must_use]
pub fn new(path: Vec<String>) -> Self {
Self {
path,
args: Vec::new(),
}
}
}
impl Field {
#[must_use]
pub fn new(label: impl Into<String>, ty: DamlType) -> Self {
Self {
label: label.into(),
ty,
}
}
}
impl Record {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
type_params: Vec::new(),
fields: Vec::new(),
}
}
}
impl Variant {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
type_params: Vec::new(),
constructors: Vec::new(),
}
}
}
impl VariantConstructor {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
payload: None,
}
}
#[must_use]
pub fn with_payload(name: impl Into<String>, payload: DamlType) -> Self {
Self {
name: name.into(),
payload: Some(payload),
}
}
}
impl Enum {
#[must_use]
pub fn new(name: impl Into<String>, constructors: Vec<String>) -> Self {
Self {
name: name.into(),
constructors,
}
}
}
impl Template {
#[must_use]
pub fn new(
name: impl Into<String>,
module_name: impl Into<String>,
package_id: impl Into<String>,
package_name: impl Into<String>,
) -> Self {
Self {
name: name.into(),
module_name: module_name.into(),
package_id: package_id.into(),
package_name: package_name.into(),
fields: Vec::new(),
choices: Vec::new(),
key: None,
}
}
}
impl Choice {
#[must_use]
pub fn new(name: impl Into<String>, argument: DamlType, returns: DamlType) -> Self {
Self {
name: name.into(),
consuming: false,
argument,
returns,
}
}
}
impl Interface {
#[must_use]
pub fn new(
name: impl Into<String>,
module_name: impl Into<String>,
package_id: impl Into<String>,
package_name: impl Into<String>,
) -> Self {
Self {
name: name.into(),
module_name: module_name.into(),
package_id: package_id.into(),
package_name: package_name.into(),
view: None,
choices: Vec::new(),
}
}
}
impl PackageModule {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
modules: Vec::new(),
}
}
}
impl NamedModule {
#[must_use]
pub fn new(name: impl Into<String>, module: Module) -> Self {
Self {
name: name.into(),
module,
}
}
}