DarFile

Struct DarFile 

Source
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: DarManifest§main: DamlLfArchive§dependencies: Vec<DamlLfArchive>

Implementations§

Source§

impl DarFile

Source

pub fn new( manifest: impl Into<DarManifest>, main: impl Into<DamlLfArchive>, dependencies: impl Into<Vec<DamlLfArchive>>, ) -> Self

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.

Source

pub fn from_file(path: impl AsRef<Path>) -> DamlLfResult<Self>

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());
Source

pub fn apply<R, F>(&self, f: F) -> DamlLfResult<R>
where F: FnOnce(&DamlArchive<'_>) -> R,

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(())
Source

pub fn to_owned_archive(&self) -> DamlLfResult<DamlArchive<'static>>

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());
Source

pub const fn manifest(&self) -> &DarManifest

The manifest information contained within this DarFile.

Source

pub const fn main(&self) -> &DamlLfArchive

The main DamlLfArchive contained within this DarFile.

Source

pub const fn dependencies(&self) -> &Vec<DamlLfArchive>

A collection of dependencies DamlLfArchive contained within this DarFile.

Trait Implementations§

Source§

impl Clone for DarFile

Source§

fn clone(&self) -> DarFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DarFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.