mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 14:30:48 +00:00
introduce CallParameters
This commit is contained in:
parent
89da1d5285
commit
48bc0e52e2
@ -18,3 +18,7 @@ proc-macro = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-sdk-wit = { path = "../wit", version = "=0.2.0" }
|
fluence-sdk-wit = { path = "../wit", version = "=0.2.0" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# Indicates that this crate is included to the Fluence Rust sdk (it affects internal path adjusting)
|
||||||
|
fce = ["fluence-sdk-wit/fce"]
|
||||||
|
@ -19,6 +19,7 @@ crate-type = ["rlib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = { version = "0.4.8", features = ["std"] }
|
log = { version = "0.4.8", features = ["std"] }
|
||||||
|
fluence-sdk-macro = { path = "../macro" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
simple_logger = "1.6.0" # used in doc test
|
simple_logger = "1.6.0" # used in doc test
|
||||||
@ -30,3 +31,6 @@ debug = []
|
|||||||
|
|
||||||
# Enable logger (this will cause log_utf8_string to appear in imports)
|
# Enable logger (this will cause log_utf8_string to appear in imports)
|
||||||
logger = []
|
logger = []
|
||||||
|
|
||||||
|
# Indicates that this crate is included to the Fluence Rust sdk (it affects internal path adjusting)
|
||||||
|
fce = ["fluence-sdk-macro/fce"]
|
||||||
|
47
crates/main/src/call_parameters.rs
Normal file
47
crates/main/src/call_parameters.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use fluence_sdk_macro::fce;
|
||||||
|
|
||||||
|
/// This struct contains parameters that would be accessible by Wasm modules.
|
||||||
|
#[fce]
|
||||||
|
#[derive(Clone, PartialEq, Default, Eq, Debug)]
|
||||||
|
pub struct CallParameters {
|
||||||
|
pub call_id: String,
|
||||||
|
pub user_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CallParameters {
|
||||||
|
pub fn new<C, U>(call_id: C, user_name: U) -> Self
|
||||||
|
where
|
||||||
|
C: Into<String>,
|
||||||
|
U: Into<String>,
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
call_id: call_id.into(),
|
||||||
|
user_name: user_name.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "fce"))]
|
||||||
|
#[fce]
|
||||||
|
#[link(wasm_import_module = "host")]
|
||||||
|
#[allow(improper_ctypes)]
|
||||||
|
extern "C" {
|
||||||
|
// returns current call parameters
|
||||||
|
pub fn get_call_parameters() -> CallParameters;
|
||||||
|
}
|
@ -31,11 +31,15 @@
|
|||||||
)]
|
)]
|
||||||
#![warn(rust_2018_idioms)]
|
#![warn(rust_2018_idioms)]
|
||||||
|
|
||||||
|
mod call_parameters;
|
||||||
mod export_allocator;
|
mod export_allocator;
|
||||||
#[cfg(any(feature = "debug", feature = "logger"))]
|
#[cfg(any(feature = "debug", feature = "logger"))]
|
||||||
mod logger;
|
mod logger;
|
||||||
mod result;
|
mod result;
|
||||||
|
|
||||||
|
pub use call_parameters::CallParameters;
|
||||||
|
#[cfg(not(feature = "fce"))]
|
||||||
|
pub use call_parameters::get_call_parameters;
|
||||||
pub use export_allocator::allocate;
|
pub use export_allocator::allocate;
|
||||||
pub use export_allocator::deallocate;
|
pub use export_allocator::deallocate;
|
||||||
#[cfg(feature = "logger")]
|
#[cfg(feature = "logger")]
|
||||||
|
@ -20,3 +20,7 @@ serde = { version = "1.0.110", features = ["derive"] }
|
|||||||
serde_json = "1.0.56"
|
serde_json = "1.0.56"
|
||||||
syn = { version = '1.0.33', features = ['full'] }
|
syn = { version = '1.0.33', features = ['full'] }
|
||||||
uuid = { version = "0.8.1", features = ["v4"] }
|
uuid = { version = "0.8.1", features = ["v4"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# Indicates that this crate is included to the Fluence Rust sdk (it affects internal path adjusting)
|
||||||
|
fce = []
|
||||||
|
@ -40,13 +40,25 @@ impl quote::ToTokens for fce_ast_types::AstRecordItem {
|
|||||||
let serializer_fn = generate_serializer_fn(self);
|
let serializer_fn = generate_serializer_fn(self);
|
||||||
let deserializer_fn = generate_deserializer_fn(self);
|
let deserializer_fn = generate_deserializer_fn(self);
|
||||||
|
|
||||||
|
#[cfg(feature = "fce")]
|
||||||
|
let trait_path = || {
|
||||||
|
quote::quote! { crate::FCEStructSerializable }
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "fce"))]
|
||||||
|
let trait_path = || {
|
||||||
|
quote::quote! { fluence::internal::FCEStructSerializable }
|
||||||
|
};
|
||||||
|
|
||||||
|
let trait_path = trait_path();
|
||||||
|
|
||||||
let glue_code = quote::quote! {
|
let glue_code = quote::quote! {
|
||||||
#original
|
#original
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(any(target_arch = "wasm32", feature = "fce"))]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[allow(clippy::all)]
|
#[allow(clippy::all)]
|
||||||
impl fluence::internal::FCEStructSerializable for #record_name {
|
impl #trait_path for #record_name {
|
||||||
#serializer_fn
|
#serializer_fn
|
||||||
|
|
||||||
#deserializer_fn
|
#deserializer_fn
|
||||||
|
@ -71,6 +71,8 @@ extern crate fluence_sdk_macro;
|
|||||||
extern crate fluence_sdk_main;
|
extern crate fluence_sdk_main;
|
||||||
|
|
||||||
pub use fluence_sdk_macro::fce;
|
pub use fluence_sdk_macro::fce;
|
||||||
|
pub use fluence_sdk_main::CallParameters;
|
||||||
|
pub use fluence_sdk_main::get_call_parameters;
|
||||||
#[cfg(feature = "logger")]
|
#[cfg(feature = "logger")]
|
||||||
pub use fluence_sdk_main::WasmLogger;
|
pub use fluence_sdk_main::WasmLogger;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user