mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 14:30:48 +00:00
get rid of trait
This commit is contained in:
parent
b3a8f3cc31
commit
f312b09fec
@ -49,19 +49,6 @@ pub use result::get_result_size;
|
||||
pub use result::set_result_ptr;
|
||||
pub use result::set_result_size;
|
||||
|
||||
/// This trait is used to convert structs to a form compatible with
|
||||
/// record.lift_memory and record.lower_memory instructions.
|
||||
/// Normally, this trait shouldn't be used directly.
|
||||
pub trait FCEStructSerializable {
|
||||
// Serialize the provided record to a Vec<u8>, returns pointer to it in a form compatible with
|
||||
// record.lift_memory.
|
||||
// The caller should manage the lifetime of returned pointer.
|
||||
fn __fce_generated_serialize(&self) -> *const u8;
|
||||
|
||||
// Deserialize record from a pointer (normally, come from record.lower_memory).
|
||||
unsafe fn __fce_generated_deserialize(record_ptr: *const u8) -> Self;
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub(crate) fn log<S: AsRef<str>>(msg: S) {
|
||||
// logs will be printed only if debug feature is enabled
|
||||
|
@ -60,8 +60,10 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
|
||||
},
|
||||
Some(ParsedType::Record(record_name)) => {
|
||||
let record_ident = new_ident!(record_name);
|
||||
let crate_path = get_crate_path();
|
||||
|
||||
quote! {
|
||||
#record_ident::__fce_generated_deserialize(fluence::internal::get_result_ptr() as _)
|
||||
#record_ident::__fce_generated_deserialize(#crate_path::get_result_ptr() as _)
|
||||
}
|
||||
}
|
||||
_ => panic!(
|
||||
@ -70,3 +72,13 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "fce")]
|
||||
fn get_crate_path() -> proc_macro2::TokenStream {
|
||||
quote! {fluence::internal}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "fce"))]
|
||||
fn get_crate_path() -> proc_macro2::TokenStream {
|
||||
quote! {crate}
|
||||
}
|
||||
|
@ -69,10 +69,6 @@ impl quote::ToTokens for fce_ast_types::AstFunctionItem {
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::all)]
|
||||
pub unsafe fn #func_name(#(#raw_arg_names: #raw_arg_types),*) #fn_return_type {
|
||||
// brings serialize/deserialize methods for records
|
||||
#[allow(dead_code)]
|
||||
use fluence::internal::FCEStructSerializable;
|
||||
|
||||
// arguments conversation from Wasm types to Rust types
|
||||
#prolog
|
||||
|
||||
|
@ -121,10 +121,6 @@ fn generate_wrapper_functions(extern_item: &fce_ast_types::AstExternModItem) ->
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::all)]
|
||||
#visibility fn #func_name(#(#arg_names: #arg_types), *) #return_type {
|
||||
// brings serialize/deserialize methods for records
|
||||
#[allow(dead_code)]
|
||||
use fluence::internal::FCEStructSerializable;
|
||||
|
||||
unsafe {
|
||||
// calling the original function with converted args
|
||||
#return_expression #import_func_name(#(#raw_args), *);
|
||||
|
@ -40,25 +40,13 @@ 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(any(target_arch = "wasm32", feature = "fce"))]
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::all)]
|
||||
impl #trait_path for #record_name {
|
||||
impl #record_name {
|
||||
#serializer_fn
|
||||
|
||||
#deserializer_fn
|
||||
|
@ -83,6 +83,4 @@ pub mod internal {
|
||||
pub use fluence_sdk_main::get_result_size;
|
||||
pub use fluence_sdk_main::set_result_ptr;
|
||||
pub use fluence_sdk_main::set_result_size;
|
||||
|
||||
pub use fluence_sdk_main::FCEStructSerializable;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user