mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 23:30:18 +00:00
introduce CallParameters
This commit is contained in:
parent
89da1d5285
commit
48bc0e52e2
@ -18,3 +18,7 @@ proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
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]
|
||||
log = { version = "0.4.8", features = ["std"] }
|
||||
fluence-sdk-macro = { path = "../macro" }
|
||||
|
||||
[dev-dependencies]
|
||||
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)
|
||||
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)]
|
||||
|
||||
mod call_parameters;
|
||||
mod export_allocator;
|
||||
#[cfg(any(feature = "debug", feature = "logger"))]
|
||||
mod logger;
|
||||
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::deallocate;
|
||||
#[cfg(feature = "logger")]
|
||||
|
@ -20,3 +20,7 @@ serde = { version = "1.0.110", features = ["derive"] }
|
||||
serde_json = "1.0.56"
|
||||
syn = { version = '1.0.33', features = ['full'] }
|
||||
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 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! {
|
||||
#original
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(any(target_arch = "wasm32", feature = "fce"))]
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::all)]
|
||||
impl fluence::internal::FCEStructSerializable for #record_name {
|
||||
impl #trait_path for #record_name {
|
||||
#serializer_fn
|
||||
|
||||
#deserializer_fn
|
||||
|
@ -71,6 +71,8 @@ extern crate fluence_sdk_macro;
|
||||
extern crate fluence_sdk_main;
|
||||
|
||||
pub use fluence_sdk_macro::fce;
|
||||
pub use fluence_sdk_main::CallParameters;
|
||||
pub use fluence_sdk_main::get_call_parameters;
|
||||
#[cfg(feature = "logger")]
|
||||
pub use fluence_sdk_main::WasmLogger;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user