24 releases (12 stable)

1.4.1 May 13, 2024
1.4.0 May 9, 2024
1.3.1-pre.3 Apr 19, 2024
1.1.1 Feb 12, 2024
0.0.1 Jul 6, 2021

#903 in Magic Beans

Download history 137/week @ 2024-02-14 183/week @ 2024-02-21 133/week @ 2024-02-28 190/week @ 2024-03-06 118/week @ 2024-03-13 236/week @ 2024-03-20 210/week @ 2024-03-27 222/week @ 2024-04-03 165/week @ 2024-04-10 725/week @ 2024-04-17 623/week @ 2024-04-24 316/week @ 2024-05-01 876/week @ 2024-05-08 331/week @ 2024-05-15 437/week @ 2024-05-22 198/week @ 2024-05-29

1,896 downloads per month
Used in 12 crates (via gstd)

GPL-3.0 license

140KB
2K SLoC

gcore

Core library for Gear programs.

Features

codec - Allows you to get actual errors occurred instead of ExtError::Some one.


lib.rs:

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;

#[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()
}

Dependencies

~1.2–1.8MB
~41K SLoC