pub struct Gas(/* private fields */);Expand description
Gas units for NEAR transactions.
§Creating Gas Amounts
Use the typed constructors for compile-time safety:
use near_kit::Gas;
// Preferred: short aliases (const, zero-cost)
let default_gas = Gas::tgas(30);
let more_gas = Gas::tgas(100);
// Common constants
let default = Gas::DEFAULT; // 30 Tgas
let max = Gas::MAX; // 1 Pgas (1000 Tgas)§Parsing from Strings
String parsing is available for runtime input:
"30 Tgas"or"30 tgas"- teragas (10^12)"5 Ggas"or"5 ggas"- gigagas (10^9)"1000000 gas"- raw gas units
use near_kit::Gas;
// For runtime/user input only
let gas: Gas = "30 Tgas".parse().unwrap();
assert_eq!(gas.as_gas(), 30_000_000_000_000);Implementations§
Source§impl Gas
impl Gas
Sourcepub const fn tgas(tgas: u64) -> Self
pub const fn tgas(tgas: u64) -> Self
Create from teragas (short alias for from_tgas).
§Example
use near_kit::Gas;
let gas = Gas::tgas(30);
assert_eq!(gas, Gas::DEFAULT);Sourcepub const fn ggas(ggas: u64) -> Self
pub const fn ggas(ggas: u64) -> Self
Create from gigagas (short alias for from_ggas).
§Example
use near_kit::Gas;
let gas = Gas::ggas(5);
assert_eq!(gas.as_ggas(), 5);Sourcepub fn checked_add(self, other: Self) -> Option<Self>
pub fn checked_add(self, other: Self) -> Option<Self>
Checked addition.
Sourcepub fn checked_sub(self, other: Self) -> Option<Self>
pub fn checked_sub(self, other: Self) -> Option<Self>
Checked subtraction.
Trait Implementations§
Source§impl BorshDeserialize for Gas
impl BorshDeserialize for Gas
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for Gas
impl BorshSerialize for Gas
Source§impl<'de> Deserialize<'de> for Gas
impl<'de> Deserialize<'de> for Gas
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Gas
impl Ord for Gas
Source§impl PartialOrd for Gas
impl PartialOrd for Gas
impl Copy for Gas
impl Eq for Gas
impl StructuralPartialEq for Gas
Auto Trait Implementations§
impl Freeze for Gas
impl RefUnwindSafe for Gas
impl Send for Gas
impl Sync for Gas
impl Unpin for Gas
impl UnsafeUnpin for Gas
impl UnwindSafe for Gas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.