1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! # Slipstream Rust SDK (Grid)
//!
//! ## Overview
//!
//! This is a library for using host functions from the [*Slipstream
//! runtime*](https://github.com/s3ndotxyz/runtime). It's more or less a wrapper for linked Wasm imports.
//!
//! ## Features
//!
//! * *kvs*. Provides access to the native in-runtime key-value store. You should be able to manage keys, values, and stores from within your functions. *Note:* stores are currently only available, one for each function.
//! * *time*. We're enabling secure time for you to do things like event scheduling. This is a work in progress.
//!
//! We have plans to enable a few other things such as message queues and web-sockets in the near
//! future. Stay tuned!
//!
//! ## Example
//!
//! Here's a simple example of a function that stores a username and a vector of bytes in the key-value store:
//!
//! ```
//! use grid_rs::{kvs::Storage};
//! use serde::{Deserialize, Serialize};
//!
//! #[grid_rs::main]
//! fn main(input: &[u8]) -> Result<Vec<u8>, String> {
//! let input: MyInput = match serde_json::from_slice(input) {
//! Ok(input) => input,
//! Err(e) => {
//! return Err(format!(
//! "JSON deserialization failed: {e}. Input was: {}",
//! String::from_utf8_lossy(input)));
//! }
//! };
//!
//! Storage::put(&input.username, &input.data);
//!
//! let output = MyOutput {
//! status: "success".to_string(),
//! result: input.data,
//! };
//!
//! Ok(serde_json::to_vec(&output).unwrap())
//! }
//!
//! #[derive(Deserialize)]
//! struct MyInput {
//! username: String,
//! data: Vec<u8>,
//! }
//!
//! #[derive(Serialize)]
//! struct MyOutput {
//! status: String,
//! result: Vec<u8>,
//! }
//! ```
pub use main;
use Region;
/// Output buffer writer.
;