Struct daml_lf::DamlLfArchive
source · [−]pub struct DamlLfArchive {
pub name: String,
pub payload: DamlLfArchivePayload,
pub hash_function: DamlLfHashFunction,
pub hash: String,
}Expand description
A Daml LF archive (aka a dalf file).
A DamlLfArchive contains a name, a payload (aka “package”), a hash (aka “package id”) of that payload for
a given hash_function.
Fields
name: Stringpayload: DamlLfArchivePayloadhash_function: DamlLfHashFunctionhash: StringImplementations
sourceimpl DamlLfArchive
impl DamlLfArchive
sourcepub fn new(
name: impl Into<String>,
payload: impl Into<DamlLfArchivePayload>,
hash_function: impl Into<DamlLfHashFunction>,
hash: impl Into<String>
) -> Self
pub fn new(
name: impl Into<String>,
payload: impl Into<DamlLfArchivePayload>,
hash_function: impl Into<DamlLfHashFunction>,
hash: impl Into<String>
) -> Self
Create an archive from an existing payload, hash_function and hash.
Note that this method does not validate that the supplied hash is valid for the supplied payload and
hash_function and thus could create an invalid archive.
sourcepub fn from_bytes(bytes: impl Into<Bytes>) -> DamlLfResult<Self>
pub fn from_bytes(bytes: impl Into<Bytes>) -> DamlLfResult<Self>
Deserialize an archive from the protobuf binary representation with a default name.
Deserialize the supplied protobuf bytes into a DamlLfArchive. The embedded payload (bytes) will also
be deserialized into a DamlLfArchivePayload.
Errors
If the provided bytes cannot be deserialized into an archive (or the embedded payload cannot be deserialized
into a DamlLfArchivePayload) then DamlLfParseError will be returned.
If the embedded payload is not of a known version then UnknownVersion will be returned.
Archives of Daml LF v0 are not supported and will result in a UnsupportedVersion being returned.
Examples
let buffer = Vec::<u8>::new();
let archive = DamlLfArchive::from_bytes(buffer)?;
assert_eq!(&DamlLfHashFunction::Sha256, archive.hash_function());sourcepub fn from_bytes_named(
name: impl Into<String>,
bytes: impl Into<Bytes>
) -> DamlLfResult<Self>
pub fn from_bytes_named(
name: impl Into<String>,
bytes: impl Into<Bytes>
) -> DamlLfResult<Self>
Deserialize a named archive from the protobuf binary representation.
Deserialize the supplied protobuf bytes into a DamlLfArchive. The embedded payload (bytes) will also
be deserialized into a DamlLfArchivePayload.
Errors
If the provided bytes cannot be deserialized into an archive (or the embedded payload cannot be deserialized
into a DamlLfArchivePayload) then DamlLfParseError will be returned.
If the embedded payload is not of a known version then UnknownVersion will be returned.
Archives of Daml LF v0 are not supported and will result in a UnsupportedVersion being returned.
Examples
let buffer = Vec::<u8>::new();
let archive = DamlLfArchive::from_bytes_named("foo", buffer)?;
assert_eq!(&DamlLfHashFunction::Sha256, archive.hash_function());
assert_eq!("foo", archive.name());sourcepub fn from_file(dalf_path: impl AsRef<Path>) -> DamlLfResult<Self>
pub fn from_file(dalf_path: impl AsRef<Path>) -> DamlLfResult<Self>
Read and parse an archive from a dalf file.
Errors
If the provided file cannot be read an IOError will be returned which contains the underlying IO error.
If the contents of the file cannot be deserialized into an archive (or the embedded payload cannot be
deserialized into a DamlLfArchivePayload) then DamlLfParseError will be returned.
If the embedded payload is not of a known version then UnknownVersion will be returned.
Archives of Daml LF v0 are not supported and will result in a UnsupportedVersion being returned.
Examples
let archive = DamlLfArchive::from_file("Example.dalf")?;
assert_eq!(&DamlLfHashFunction::Sha256, archive.hash_function());
assert_eq!("Example", archive.name());sourcepub fn apply<R, F>(&self, f: F) -> DamlLfResult<R> where
F: FnOnce(&DamlPackage<'_>) -> R,
pub fn apply<R, F>(&self, f: F) -> DamlLfResult<R> where
F: FnOnce(&DamlPackage<'_>) -> R,
Create a DamlArchive from a DamlLfArchive and apply it to f.
See DarFile::apply for details.
sourcepub const fn payload(&self) -> &DamlLfArchivePayload
pub const fn payload(&self) -> &DamlLfArchivePayload
The payload (aka “package”) contained within this archive.
sourcepub const fn hash_function(&self) -> &DamlLfHashFunction
pub const fn hash_function(&self) -> &DamlLfHashFunction
The hashing function used to generate this archives hash.
Trait Implementations
sourceimpl Clone for DamlLfArchive
impl Clone for DamlLfArchive
sourcefn clone(&self) -> DamlLfArchive
fn clone(&self) -> DamlLfArchive
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
Auto Trait Implementations
impl RefUnwindSafe for DamlLfArchive
impl Send for DamlLfArchive
impl Sync for DamlLfArchive
impl Unpin for DamlLfArchive
impl UnwindSafe for DamlLfArchive
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