logo
pub struct DarFile {
    pub manifest: DarManifest,
    pub main: DamlLfArchive,
    pub dependencies: Vec<DamlLfArchive>,
}
Expand description

A collection of Daml LF archives combined with a manifest file (aka a dar file).

A DarFile contains a main DamlLfArchive and collection of dependencies DamlLfArchive combined with a DarManifest.

Fields

manifest: DarManifestmain: DamlLfArchivedependencies: Vec<DamlLfArchive>

Implementations

Create a new DarFile from an existing manifest file, main and dependencies DamlLfArchive.

Note that this method does not validate that the supplied manifest correctly reflects the main and dependencies DamlLfArchive provided and so may yield an invalid DarFile.

Create a DarFile from the supplied dar file.

There are currently two supported dar formats supported by this module, legacy and fat. Parsing will first attempt to parse a fat dar. If parsing fails an attempt will be made to parse a legacy dar instead.

Dar Format

Both formats are compressed zip archives with a dar extension which contain a META-INF/MANIFEST.MF file and one or more dalf files, potentially nested in a sub folders.

If dar file provided does not contain a manifest or if the manifest does not contain all mandatory fields then parsing will fail.

The manifest file of legacy dar files will not be read, instead it will be inferred from the set of dalf files within the file. The following combinations are considered valid for legacy dar files:

  • A dar file containing only a single non-prim dalf file (anywhere)
  • A dar file containing a single non-prim dalf file and a single prim dalf file (ending with the -prim suffix)
  • A dar file containing only a single prim (ending with the -prim suffix) file
Errors

If the file cannot be read then an IoError will be returned.

If the file cannot be interpreted as a zip archive then a DarParseError will be returned.

Should both fat and legacy parsing attempts fail then a DarParseError will be returned.

Examples
let dar = DarFile::from_file("Example.dar")?;
assert_eq!(&DamlLfHashFunction::Sha256, dar.main().hash_function());

Create a DamlArchive from this DarFile and apply it to f.

The created DamlArchive borrows all interned string data from this DarFile and is therefore tied to the lifetime of the DarFile and so cannot be returned from this scope. The DamlArchive can be accessed from the supplied closure f which may return owned data.

Use DarFile::to_owned_archive to create a DamlArchive which does not borrow any data from the generating DarFile.

Examples
let dar = DarFile::from_file("Example.dar")?;
// create a DamlArchive from this DarFile and extract the (owned) name.
let name = dar.apply(|archive| archive.name().to_owned())?;
assert_eq!("Example-1.0.0", name);
Ok(())

Create an owned DamlArchive from this DarFile.

This is an expensive operation as it involves both a conversion of the DarFile to a DamlArchive (which borrows all interned strings) and a subsequent conversion to an owned DamlArchive which clones all interned strings.

Use this when an owned instance of a DamlArchive is required, such as for passing to a thread. For other cases consider using the DarFile::apply method which does not require the second conversion.

Examples
let dar = DarFile::from_file("Example.dar")?;
let archive = dar.to_owned_archive()?;
assert_eq!("TestingTypes-1.0.0", archive.name());

The manifest information contained within this DarFile.

The main DamlLfArchive contained within this DarFile.

A collection of dependencies DamlLfArchive contained within this DarFile.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.