#fluence #sdk #webassembly #procedural-macros

macro fluence-sdk-macro

Definition of the #[fce] macro

38 releases (5 breaking)

new 0.6.1 Apr 27, 2021
0.5.0 Mar 12, 2021
0.4.2 Feb 28, 2021
0.2.14 Dec 31, 2020
0.1.4 Mar 27, 2019

#278 in WebAssembly

Download history 162/week @ 2021-01-07 233/week @ 2021-01-14 176/week @ 2021-01-21 123/week @ 2021-01-28 195/week @ 2021-02-04 381/week @ 2021-02-11 262/week @ 2021-02-18 352/week @ 2021-02-25 260/week @ 2021-03-04 335/week @ 2021-03-11 212/week @ 2021-03-18 300/week @ 2021-03-25 143/week @ 2021-04-01 221/week @ 2021-04-08 551/week @ 2021-04-15 231/week @ 2021-04-22

1,145 downloads per month
Used in 17 crates (2 directly)

Apache-2.0

115KB
2.5K SLoC

crates.io version

Rust backend SDK

This SDK intended to run backend application on the Fluence network. More information about usage and some internals could found in docs.


lib.rs:

Defines the #[fce] macro that should be used with all export functions, extern blocks. At now, It supports the following types that could be used as parameters in export or foreign functions: i8, i16, i32, i64, u8, u16, u32, u64, f32, f64, bool, String, Vec. Also struct where all fields are public and have aforementioned types could be used as parameters. In this case #[fce] should be also applied to this structs.

Examples

This example shows how a function could be exported:

#[fce]
pub fn greeting(name: String) -> String {
    format!("Hi {}", name)
}

This more complex example shows how a function could be imported from another Wasm module and how a struct could be passed:

use fluence::MountedBinaryResult;

#[fce]
pub fn read_ipfs_file(file_path: String) -> MountedBinaryResult {
    let hash = calculate_hash(file_path);
    ipfs(vec![hash])
}

#[fce]
#[link(wasm_import_module = "ipfs_node")]
extern "C" {
    pub fn ipfs(file_hash: Vec<String>) -> MountedBinaryResult;
}

Dependencies

~1.3–2MB
~43K SLoC