Struct gstd::ReservationId
source · pub struct ReservationId(/* private fields */);Expand description
Reservation identifier.
The identifier is used to reserve and unreserve gas amount for program execution later.
Examples
use gstd::ReservationId;
static mut RESERVED: Option<ReservationId> = None;
#[no_mangle]
extern "C" fn init() {
let reservation_id = ReservationId::reserve(50_000_000, 7).expect("Unable to reserve");
unsafe { RESERVED = Some(reservation_id) };
}
#[no_mangle]
extern "C" fn handle() {
let reservation_id = unsafe { RESERVED.take().expect("Empty `RESERVED`") };
reservation_id.unreserve().expect("Unable to unreserve");
}Implementations§
source§impl ReservationId
impl ReservationId
sourcepub fn reserve(amount: u64, duration: u32) -> Result<Self>
pub fn reserve(amount: u64, duration: u32) -> Result<Self>
Reserve the amount of gas for further usage.
duration is the block count within which the reserve must be used.
This function returns ReservationId, which one can use for gas
unreserving.
Examples
Reserve 50 million of gas for one block, send a reply, then unreserve gas back:
use gstd::{msg, ReservationId};
#[no_mangle]
extern "C" fn handle() {
let reservation_id = ReservationId::reserve(50_000_000, 1).expect("Unable to reserve");
msg::reply_bytes_from_reservation(reservation_id.clone(), b"PONG", 0)
.expect("Unable to reply");
let reservation_left = reservation_id.unreserve().expect("Unable to unreserve");
}Trait Implementations§
source§impl AsRef<[u8]> for ReservationId
impl AsRef<[u8]> for ReservationId
source§impl Clone for ReservationId
impl Clone for ReservationId
source§fn clone(&self) -> ReservationId
fn clone(&self) -> ReservationId
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for ReservationId
impl Debug for ReservationId
source§impl Decode for ReservationId
impl Decode for ReservationId
source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy ) -> Result<Self, Error>
Attempt to deserialise the value from input.
source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
source§impl Encode for ReservationId
impl Encode for ReservationId
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
Convert self to a slice and append it to the destination.
source§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>(
&self,
f: __CodecUsingEncodedCallback
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback ) -> __CodecOutputReturn
Convert self to a slice and then invoke the given closure with it.
source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
source§impl From<Reservation> for ReservationId
impl From<Reservation> for ReservationId
source§fn from(res: Reservation) -> Self
fn from(res: Reservation) -> Self
Converts to this type from the input type.
source§impl From<ReservationId> for ReservationId
impl From<ReservationId> for ReservationId
source§fn from(id: ReservationId) -> Self
fn from(id: ReservationId) -> Self
Converts to this type from the input type.
source§impl From<ReservationId> for ReservationId
impl From<ReservationId> for ReservationId
source§fn from(id: ReservationId) -> Self
fn from(id: ReservationId) -> Self
Converts to this type from the input type.
source§impl Hash for ReservationId
impl Hash for ReservationId
source§impl Ord for ReservationId
impl Ord for ReservationId
source§fn cmp(&self, other: &ReservationId) -> Ordering
fn cmp(&self, other: &ReservationId) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for ReservationId
impl PartialEq for ReservationId
source§fn eq(&self, other: &ReservationId) -> bool
fn eq(&self, other: &ReservationId) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd for ReservationId
impl PartialOrd for ReservationId
source§fn partial_cmp(&self, other: &ReservationId) -> Option<Ordering>
fn partial_cmp(&self, other: &ReservationId) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresource§impl TypeInfo for ReservationId
impl TypeInfo for ReservationId
impl Copy for ReservationId
impl EncodeLike for ReservationId
impl Eq for ReservationId
impl StructuralEq for ReservationId
impl StructuralPartialEq for ReservationId
Auto Trait Implementations§
impl RefUnwindSafe for ReservationId
impl Send for ReservationId
impl Sync for ReservationId
impl Unpin for ReservationId
impl UnwindSafe for ReservationId
Blanket Implementations§
§impl<T, U> AsByteSlice<T> for U
impl<T, U> AsByteSlice<T> for U
fn as_byte_slice(&self) -> &[u8]
§impl<U> AsSliceOf for U
impl<U> AsSliceOf for U
fn as_slice_of<T>(&self) -> Result<&[T], Error>where
T: FromByteSlice,
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> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> ToHex for T
impl<T> ToHex for T
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Lower case
letters are used (e.g. f9b4ca)source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)