Crate gcore

Source
Expand description

Lightweight library for use in Gear programs.

This library should be used as a standard library when writing Gear programs. Compared to gstd crate, this library provides lower-level primitives that allow you to develop less expensive programs. Choose it if you are ready to write more code but get a more efficient Wasm.

Note that you are to define panic and out-of-memory handlers, as the crate does not provide them by default.

§Examples

#![no_std]
#![feature(alloc_error_handler)]

extern crate galloc;

use gcore::msg;

#[unsafe(no_mangle)]
extern "C" fn handle() {
    let mut bytes = [0; 64];
    msg::read(&mut bytes).expect("Unable to read");
    if let Ok(payload) = core::str::from_utf8(&bytes) {
        if payload == "PING" {
            msg::reply(b"PONG", 0).expect("Unable to reply");
        }
    }
}

#[alloc_error_handler]
pub fn oom(_: core::alloc::Layout) -> ! {
    core::arch::wasm32::unreachable()
}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    core::arch::wasm32::unreachable()
}

Re-exports§

pub use gear_stack_buffer as stack_buffer;

Modules§

errors
Type definitions and helpers for error handling.
exec
Utility functions related to the current execution context or program execution flow.
ext
Extensions for additional features.
msg
Messaging API for Gear programs.
prog
API for creating programs from Gear programs.

Macros§

debug
Add a debug message to the log.
static_mut
Get mutable reference to static mut.
static_ref
Get shared reference to static mut.

Structs§

ActorId
Program (actor) identifier.
CodeId
Code identifier.
EnvVars
Current version of execution settings.
GasMultiplier
Type representing converter between gas and value.
MessageHandle
Message handle.
MessageId
Message identifier.
Percent
Basic struct for working with integer percentages allowing values greater than 100.
ReservationId
Reservation identifier.
Ss58Address
Represents SS58 address.

Type Aliases§

BlockCount
Represents block count type.
BlockNumber
Represents block number type.
Gas
Represents gas type.
Value
Represents value type.