pub struct Artifact { /* private fields */ }
Expand description

An entity that contains compiled contracts.

Implementations§

source§

impl Artifact

source

pub fn new() -> Self

Creates a new empty artifact.

source

pub fn with_origin(origin: impl Into<String>) -> Self

Creates a new artifact with an origin information.

source

pub fn origin(&self) -> &str

Provides description of where this artifact comes from.

This function is used when a human-readable reference to the artifact is required. It could be anything: path to a json file, url, etc.

source

pub fn set_origin(&mut self, origin: impl Into<String>)

Sets new origin for the artifact.

Artifact loaders will set origin to something meaningful in most cases, so this function should not be used often. There are cases when it is required, though.

source

pub fn len(&self) -> usize

Gets number of contracts contained in this artifact.

source

pub fn is_empty(&self) -> bool

Returns true if this artifact contains no contracts.

source

pub fn contains(&self, name: &str) -> bool

Returns true if this artifact has a contract with the given name.

source

pub fn get(&self, name: &str) -> Option<&Contract>

Looks up contract by its name and returns a reference to it.

Some artifact formats allow exporting a single unnamed contract. In this case, the contract will have an empty string as its name.

source

pub fn get_mut(&mut self, name: &str) -> Option<ContractMut<'_>>

Looks up contract by its name and returns a handle that allows safely mutating it.

The returned handle does not allow renaming contract. For that, you’ll need to remove it and add again.

source

pub fn insert(&mut self, contract: Contract) -> InsertResult<'_>

Inserts a new contract to the artifact.

If contract with this name already exists, replaces it and returns the old contract.

source

pub fn remove(&mut self, name: &str) -> Option<Contract>

Removes contract from the artifact.

Returns removed contract or None if contract with the given name wasn’t found.

source

pub fn iter(&self) -> impl Iterator<Item = &Contract> + '_

Creates an iterator that yields the artifact’s contracts.

source

pub fn drain(&mut self) -> impl Iterator<Item = Contract> + '_

Takes all contracts from the artifact, leaving it empty, and returns an iterator over the taken contracts.

Trait Implementations§

source§

impl Default for Artifact

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.