30 releases (18 stable)

1.6.2 Oct 7, 2024
1.5.0 Aug 12, 2024
1.4.2 Jul 2, 2024
1.1.1 Feb 12, 2024
0.0.1 Jul 6, 2021

#27 in #gear

Download history 607/week @ 2024-07-29 361/week @ 2024-08-05 665/week @ 2024-08-12 340/week @ 2024-08-19 352/week @ 2024-08-26 368/week @ 2024-09-02 234/week @ 2024-09-09 326/week @ 2024-09-16 1043/week @ 2024-09-23 546/week @ 2024-09-30 743/week @ 2024-10-07 574/week @ 2024-10-14 651/week @ 2024-10-21 361/week @ 2024-10-28 577/week @ 2024-11-04 207/week @ 2024-11-11

1,827 downloads per month
Used in 15 crates (via gstd)

GPL-3.0 license

185KB
2.5K 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

~3.5MB
~66K SLoC