Asset

Struct Asset 

Source
pub struct Asset {
    pub amount: i64,
    pub symbol: Symbol,
}
Expand description

The Asset struct represents a asset

Reference: https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/asset.hpp

§Examples

use antelope::{Asset, Symbol};

let quantity = Asset::from_amount(10000, Symbol::from("4,FOO"));
assert_eq!(10000, quantity.amount);

Fields§

§amount: i64§symbol: Symbol

Implementations§

Source§

impl Asset

Source

pub const MAX_AMOUNT: i64 = 4_611_686_018_427_387_903i64

Source

pub fn new() -> Self

Source

pub fn from_amount(amount: i64, symbol: Symbol) -> Self

Source

pub fn is_amount_within_range(&self) -> bool

Check if the amount doesn’t exceed the max amount

@return true - if the amount doesn’t exceed the max amount @return false - otherwise

Source

pub fn is_valid(&self) -> bool

Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid

@return true - if the asset is valid @return false - otherwise

Source

pub fn set_amount(self, amount: i64)

Set the amount of the asset

@param a - New amount for the asset

Source

pub fn value(&self) -> f64

@return float value of amount

Trait Implementations§

Source§

impl Add for Asset

Source§

fn add(self, other: Self) -> Self

Addition operator

@param other - The second asset to be added to the first asset @return asset - New asset as the result of addition

Source§

type Output = Asset

The resulting type after applying the + operator.
Source§

impl AddAssign for Asset

Source§

fn add_assign(&mut self, a: Self)

Addition Assignment operator

@param a - Another asset to add with this asset @post The amount of this asset is added with the amount of asset a

Source§

impl AsRef<Asset> for Asset

Source§

fn as_ref(&self) -> &Asset

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Asset

Source§

fn clone(&self) -> Asset

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 Asset

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Asset

Source§

fn default() -> Asset

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

impl Display for Asset

Source§

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

Converts the asset into string

@return String in the form of “1.2345 SYM” format, where SYM symbol has precision equal to 4

Source§

impl Div<i64> for Asset

Source§

fn div(self, b: i64) -> Asset

Division operator, with a number proceeding

@param a - The asset to be divided @param b - The divisor for the asset’s amount @return asset - New asset as the result of division

Source§

type Output = Asset

The resulting type after applying the / operator.
Source§

impl Div for Asset

Source§

fn div(self, b: Asset) -> Self::Output

Division operator, with another asset

@param a - The asset which amount acts as the dividend @param b - The asset which amount acts as the divisor @return int64_t - the resulted amount after the division @pre Both asset must have the same symbol

Source§

type Output = i64

The resulting type after applying the / operator.
Source§

impl DivAssign<i64> for Asset

Source§

fn div_assign(&mut self, a: i64)

Division assignment operator, with a number proceeding

@brief Division assignment operator, with a number proceeding @param self - The asset to be divided @param a - The divisor for the asset’s amount @return asset - Reference to the asset, which has been divided

Source§

impl From<&str> for Asset

Source§

fn from(s: &str) -> Self

Parse Asset from string formatted as “1.2345 SYM@contract”

Source§

impl FromStr for Asset

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Mul<Asset> for i64

Source§

fn mul(self, a: Asset) -> Asset

Multiplication operator, with a number preceeding

@param a - The multiplier for the asset’s amount @param b - The asset to be multiplied @return asset - New asset as the result of multiplication

Source§

type Output = Asset

The resulting type after applying the * operator.
Source§

impl Mul<i64> for Asset

Source§

fn mul(self, b: i64) -> Asset

Multiplication operator, with a number proceeding

@brief Multiplication operator, with a number proceeding @param a - The asset to be multiplied @param b - The multiplier for the asset’s amount @return asset - New asset as the result of multiplication

Source§

type Output = Asset

The resulting type after applying the * operator.
Source§

impl MulAssign<i64> for Asset

Source§

fn mul_assign(&mut self, a: i64)

Multiplication assignment operator, with a number

@details Multiplication assignment operator. Multiply the amount of this asset with a number and then assign the value to itself. @param a - The multiplier for the asset’s amount @return asset - Reference to this asset @post The amount of this asset is multiplied by a

Source§

impl Neg for Asset

Source§

fn neg(self) -> Asset

Negate the amount of the asset

@return a new asset with the negated amount

Source§

type Output = Asset

The resulting type after applying the - operator.
Source§

impl Ord for Asset

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Asset

Source§

fn eq(&self, other: &Asset) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Asset

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Asset

Source§

fn sub(self, other: Self) -> Self

Subtraction operator

@param other - The asset used to subtract from the first asset @return asset - New asset as the result of subtraction

Source§

type Output = Asset

The resulting type after applying the - operator.
Source§

impl SubAssign for Asset

Source§

fn sub_assign(&mut self, other: Asset)

Subtraction assignment operator

@param other - Another asset to subtract this asset with @post The amount of this asset is subtracted by the amount of asset other

Source§

impl Copy for Asset

Source§

impl Eq for Asset

Auto Trait Implementations§

§

impl Freeze for Asset

§

impl RefUnwindSafe for Asset

§

impl Send for Asset

§

impl Sync for Asset

§

impl Unpin for Asset

§

impl UnwindSafe for Asset

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.