DamlLfArchive

Struct 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: String§payload: DamlLfArchivePayload§hash_function: DamlLfHashFunction§hash: String

Implementations§

Source§

impl DamlLfArchive

Source

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.

Source

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

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

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

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.

Source

pub fn name(&self) -> &str

The name of this archive.

Source

pub const fn payload(&self) -> &DamlLfArchivePayload

The payload (aka “package”) contained within this archive.

Source

pub const fn hash_function(&self) -> &DamlLfHashFunction

The hashing function used to generate this archives hash.

Source

pub fn hash(&self) -> &str

The hash of this archive (aka “package id”).

Trait Implementations§

Source§

impl Clone for DamlLfArchive

Source§

fn clone(&self) -> DamlLfArchive

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 DamlLfArchive

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.