daml_lf/lib.rs
1//! A library for working with `Daml-LF`.
2//!
3//! Compiled `Daml` packages are represented as [`Daml-LF`](https://github.com/digital-asset/daml/tree/main/daml-lf) (
4//! aka "Ledger Fragment") archives. An archive is a protobuf serialized bytes array which is typically stored in a
5//! `dalf` file. Multiple `dalf` archives can be combined along with a manifest file into a `Dar` ("Daml Archive")
6//! file.
7//!
8//! # Elements
9//!
10//! The [`element`] module contains a higher level representation of all Daml-LF types and provide several convenience
11//! methods to simplify working with Daml-LF types over the raw types generated from the protobuf definitions.
12//!
13//! These types are typically constructed by converting an existing [`DarFile`], [`DamlLfArchive`] or
14//! [`DamlLfArchivePayload`] which can be loaded from a file or downloaded from a Daml ledger.
15//!
16//! In the following example the `example.dar` is loaded from a file, converted to a `DamlArchive` and finally the id
17//! of the main package is extracted:
18//!
19//! ```no_run
20//! # use daml_lf::DarFile;
21//! # use daml_lf::DamlLfResult;
22//! # fn main() -> DamlLfResult<()> {
23//! let dar = DarFile::from_file("Example.dar")?;
24//! let package_id = dar.apply(|archive| archive.main_package_id().to_owned())?;
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! # Interning
30//!
31//! Interned data is automatically managed by the [`element`] items. During conversion all [`element`] items borrow
32//! interned data from the underlying source and so no additional allocations are required per element.
33//!
34//! However if an owned (i.e. bounded by `'static`) version is required, such as to pass to a thread or an async
35//! executors, the method [`DarFile::to_owned_archive`] is provided to perform this conversion and allocate separate
36//! copies of all interned data per [`element`] as required.
37//!
38//! The following example loads `Example.dar` from a file, converts it to an owned
39//! [`DamlArchive`](`element::DamlArchive`) that is suitable to be passed to a new thread:
40//!
41//! ```no_run
42//! # use daml_lf::DarFile;
43//! # use daml_lf::DamlLfResult;
44//! # use std::thread;
45//! # fn main() -> DamlLfResult<()> {
46//! let archive = DarFile::from_file("Example.dar")?.to_owned_archive()?;
47//! thread::spawn(move || {
48//! dbg!(archive.name());
49//! })
50//! # .join().unwrap();
51//! # Ok(())
52//! # }
53//! ```
54//!
55//! # Features
56//!
57//! The following features are defined:
58//!
59//! - `default` Includes all `Daml-LF` types _except_ Daml expressions.
60//! - `full` Includes all `Daml-LF` types.
61//!
62//! # Downloading Daml Packages
63//!
64//! Serialized `Daml-LF` archives may also be retrieved from an existing ledger via the `GetPackage` method of the GRPC
65//! `package_service` (see [here](https://github.com/digital-asset/daml/blob/main/ledger-api/grpc-definitions/com/daml/ledger/api/v1/package_service.proto)).
66//! The `daml-grpc` create provides an implementation of this service in the [`daml_package_service`] module.
67//!
68//! The [`daml-util`] crate provides the [`DamlPackages`] helper to simplify downloading of packages form a Daml
69//! ledger and converting to a [`DarFile`] or collections of [`DamlLfArchive`] or [`DamlLfArchivePayload`].
70//!
71//! # Versions
72//!
73//! This library supports all Daml-LF [`LanguageVersion`] from [`LanguageVersion::V1_0`] up to
74//! [`LanguageVersion::V1_14`].
75//!
76//! [`daml-util`]: https://docs.rs/daml-util/0.2.2/daml_util/
77//! [`DamlPackages`]: https://docs.rs/daml-util/0.2.2/daml_util/package/struct.DamlPackages.html
78//! [`daml_package_service`]: https://docs.rs/daml-grpc/0.2.2/daml_grpc/service/struct.DamlPackageService.html
79#![warn(clippy::all, clippy::pedantic, clippy::nursery, rust_2018_idioms)]
80#![allow(
81 clippy::module_name_repetitions,
82 clippy::use_self,
83 clippy::cast_sign_loss,
84 clippy::must_use_candidate,
85 clippy::missing_const_for_fn,
86 clippy::missing_errors_doc
87)]
88#![forbid(unsafe_code)]
89#![doc(html_favicon_url = "https://docs.daml.com/_static/images/favicon/favicon-32x32.png")]
90#![doc(html_logo_url = "https://docs.daml.com/_static/images/DAML_Logo_Blue.svg")]
91#![doc(html_root_url = "https://docs.rs/daml-lf/0.2.2")]
92
93mod archive;
94mod convert;
95mod dar;
96mod error;
97mod lf_protobuf;
98mod manifest;
99mod package_info;
100mod payload;
101mod version;
102
103/// Representation of Daml types.
104pub mod element;
105
106// reexport types
107pub use archive::{DamlLfArchive, DamlLfHashFunction, DEFAULT_ARCHIVE_NAME};
108pub use dar::DarFile;
109pub use error::{DamlLfError, DamlLfResult};
110pub use manifest::{DarEncryptionType, DarManifest, DarManifestFormat, DarManifestVersion};
111pub use package_info::PackageInfo;
112pub use payload::{DamlLfArchivePayload, DamlLfPackage};
113pub use version::{LanguageFeatureVersion, LanguageV1MinorVersion, LanguageVersion};