fluence/
lib.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Rust backend SDK for applications on the Fluence network. This crate defines the procedure macro
18//! `#[marine]` that could be applied to a function, structure or extern block.
19//!
20//! Structures with `#[marine]` (hereinafter they'll be called records) could be used then in function
21//! arguments and values. All fields of a record should be public and have one of the
22//! following primitive Rust types
23//! (`bool, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64, String, Vec<u8>`).
24//! ```rust
25//! use fluence::marine;
26//!
27//! #[marine]
28//! struct T {
29//!     pub field_1: i32,
30//!     pub field_2: Vec<u8>,
31//! }
32//! ```
33//!
34//! Functions with `#[marine]` will be exported from this module:
35//!
36//! ```rust
37//! use fluence::marine;
38//!
39//! #[marine]
40//! pub fn get(url: String) {
41//!     // ...
42//! }
43//! ```
44//! At now, such functions could have arguments with primitive Rust types and record and only one
45//! return argument with such type could be used.
46//!
47//! Finally, to import other wasm modules to your project use similar code:
48//! ```rust
49//! use fluence::marine;
50//!
51//! #[marine]
52//! #[link(wasm_import_module = "wasm_curl.wasm")]
53//! extern "C" {
54//!     #[link_name = "get"]
55//!     pub fn curl_get(url: String) -> String;
56//! }
57//! ```
58#![doc(html_root_url = "https://docs.rs/fluence/0.6.9")]
59#![deny(
60    dead_code,
61    nonstandard_style,
62    unused_imports,
63    unused_mut,
64    unused_variables,
65    unused_unsafe,
66    unreachable_patterns
67)]
68#![warn(rust_2018_idioms)]
69
70mod call_parameters;
71mod mounted_binary;
72
73#[allow(unused_extern_crates)]
74// fluence is used inside CallParameters and MountedBinaryResult glue code
75extern crate self as fluence;
76
77pub use marine_macro::marine;
78pub use marine_macro::fce;
79
80pub use call_parameters::CallParameters;
81pub use call_parameters::SecurityTetraplet;
82pub use call_parameters::get_call_parameters;
83
84#[cfg(feature = "logger")]
85pub use fluence_sdk_main::WasmLoggerBuilder;
86#[cfg(feature = "logger")]
87pub use fluence_sdk_main::TargetMap;
88
89pub use mounted_binary::MountedBinaryResult;
90pub use mounted_binary::MountedBinaryStringResult;
91pub use mounted_binary::SUCCESS_CODE as BINARY_SUCCESS_CODE;
92
93pub use fluence_sdk_main::module_manifest;
94
95/// These API functions are intended for internal usage in generated code.
96/// Normally, you shouldn't use them.
97pub mod internal {
98    pub use fluence_sdk_main::get_result_ptr;
99    pub use fluence_sdk_main::get_result_size;
100    pub use fluence_sdk_main::set_result_ptr;
101    pub use fluence_sdk_main::set_result_size;
102    pub use fluence_sdk_main::add_object_to_release;
103    pub use marine_timestamp_macro::build_timestamp;
104}