fn generate_wasm_interface(impls: &[ItemImpl]) -> Result<TokenStream> {
	let input = Ident::new("input", Span::call_site());
	let c = generate_crate_access(HIDDEN_INCLUDES_ID);
	let impl_calls = generate_impl_calls(impls, &input)?
		.into_iter()
		.map(|(trait_, fn_name, impl_)| {
			let fn_name = Ident::new(
				&prefix_function_with_trait(&trait_, &fn_name),
				Span::call_site()
			);

			quote!(
				#[cfg(not(feature = "std"))]
				#[no_mangle]
				pub fn #fn_name(input_data: *mut u8, input_len: usize) -> u64 {
					let mut #input = if input_len == 0 {
						&[0u8; 0]
					} else {
						unsafe {
							#c::runtime_api::slice::from_raw_parts(input_data, input_len)
						}
					};

					let output = { #impl_ };
					let res = output.as_ptr() as u64 + ((output.len() as u64) << 32);

					// Leak the output vector to avoid it being freed.
					// This is fine in a WASM context since the heap
					// will be discarded after the call.
					#c::runtime_api::mem::forget(output);
					res
				}
			)
		});

	Ok(quote!( #( #impl_calls )* ))
}
/// Generate the interface functions that are used to call into the runtime in wasm.
Generate the interface functions that are used to call into the runtime in wasm.
Generate the interface functions that are used to call into the runtime in wasm .
fn generate_wasm_interface(impls: &[ItemImpl]) -> Result<TokenStream> {
	let input = Ident::new("input", Span::call_site());
	let c = generate_crate_access(HIDDEN_INCLUDES_ID);
	let impl_calls = generate_impl_calls(impls, &input)?
		.into_iter()
		.map(|(trait_, fn_name, impl_)| {
			let fn_name = Ident::new(
				&prefix_function_with_trait(&trait_, &fn_name),
				Span::call_site()
			);
			quote!(
				#[cfg(not(feature = "std"))]
				#[no_mangle]
				pub fn #fn_name(input_data: *mut u8, input_len: usize) -> u64 {
					let mut #input = if input_len == 0 {
						&[0u8; 0]
					} else {
						unsafe {
							#c::runtime_api::slice::from_raw_parts(input_data, input_len)
						}
					};
					let output = { #impl_ };
					let res = output.as_ptr() as u64 + ((output.len() as u64) << 32);
					// Leak the output vector to avoid it being freed.
					// This is fine in a WASM context since the heap
					// will be discarded after the call.
					#c::runtime_api::mem::forget(output);
					res
				}
			)
		});
	Ok(quote!( #( #impl_calls )* ))
}
fn generate_wasm_interface ( impls : & [ ItemImpl ] ) -> Result < TokenStream > { let input = Ident :: new ( " " , Span :: call_site ( ) ) ; let c = generate_crate_access ( HIDDEN_INCLUDES_ID ) ; let impl_calls = generate_impl_calls ( impls , & input ) ? . into_iter ( ) . map ( | ( trait_ , fn_name , impl_ ) | { let fn_name = Ident :: new ( & prefix_function_with_trait ( & trait_ , & fn_name ) , Span :: call_site ( ) ) ; quote ! ( [ cfg ( not ( feature " " ) ) ] [ no_mangle ] pub fn fn_name ( input_data mut u8 input_len usize ) u64 { let mut input if input_len 0 { [ 0u8 0 ] } else { unsafe { c runtime_api slice from_raw_parts ( input_data input_len ) } } let output { impl_ } let res output as_ptr ( ) as u64 ( ( output len ( ) as u64 ) 32 ) // Leak the output vector to avoid it being freed. // This is fine in a WASM context since the heap // will be discarded after the call. c runtime_api mem forget ( output ) res } ) } ) ; Ok ( quote ! ( ( impl_calls ) ) ) }
Generate the interface functions that are used to call into the runtime in wasm.
Generate the interface functions that are used to call into the runtime in wasm .
impls
&[ItemImpl]
impls
&[ItemImpl]