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
sourceimpl DarFile
impl DarFile
sourcepub fn new(
manifest: impl Into<DarManifest>,
main: impl Into<DamlLfArchive>,
dependencies: impl Into<Vec<DamlLfArchive>>
) -> Self
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.
sourcepub fn from_file(path: impl AsRef<Path>) -> DamlLfResult<Self>
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
darfile containing only a single non-primdalffile (anywhere) - A
darfile containing a single non-primdalffile and a single primdalffile (ending with the-primsuffix) - A
darfile containing only a single prim (ending with the-primsuffix) 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());sourcepub fn apply<R, F>(&self, f: F) -> DamlLfResult<R> where
F: FnOnce(&DamlArchive<'_>) -> R,
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(())sourcepub fn to_owned_archive(&self) -> DamlLfResult<DamlArchive<'static>>
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());sourcepub const fn manifest(&self) -> &DarManifest
pub const fn manifest(&self) -> &DarManifest
The manifest information contained within this DarFile.
sourcepub const fn main(&self) -> &DamlLfArchive
pub const fn main(&self) -> &DamlLfArchive
The main DamlLfArchive contained within this DarFile.
sourcepub const fn dependencies(&self) -> &Vec<DamlLfArchive>
pub const fn dependencies(&self) -> &Vec<DamlLfArchive>
A collection of dependencies DamlLfArchive contained within this DarFile.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for DarFile
impl Send for DarFile
impl Sync for DarFile
impl Unpin for DarFile
impl UnwindSafe for DarFile
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more