mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -17,14 +17,15 @@
|
||||
|
||||
//! Provides implementations for the runtime interface traits.
|
||||
|
||||
use crate::{
|
||||
RIType, Pointer, pass_by::{PassBy, Codec, Inner, PassByInner, Enum},
|
||||
util::{unpack_ptr_and_len, pack_ptr_and_len},
|
||||
};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::host::*;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use crate::wasm::*;
|
||||
use crate::{
|
||||
pass_by::{Codec, Enum, Inner, PassBy, PassByInner},
|
||||
util::{pack_ptr_and_len, unpack_ptr_and_len},
|
||||
Pointer, RIType,
|
||||
};
|
||||
|
||||
#[cfg(all(not(feature = "std"), not(feature = "disable_target_static_assertions")))]
|
||||
use static_assertions::assert_eq_size;
|
||||
@@ -32,7 +33,7 @@ use static_assertions::assert_eq_size;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_wasm_interface::{FunctionContext, Result};
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
use sp_std::{any::TypeId, mem, vec::Vec};
|
||||
|
||||
@@ -195,7 +196,7 @@ impl<T: 'static + Decode> FromFFIValue for Vec<T> {
|
||||
let len = len as usize;
|
||||
|
||||
if len == 0 {
|
||||
return Vec::new();
|
||||
return Vec::new()
|
||||
}
|
||||
|
||||
let data = unsafe { Vec::from_raw_parts(ptr as *mut u8, len, len) };
|
||||
@@ -230,7 +231,8 @@ impl<T: 'static + Decode> FromFFIValue for [T] {
|
||||
if TypeId::of::<T>() == TypeId::of::<u8>() {
|
||||
Ok(unsafe { mem::transmute(vec) })
|
||||
} else {
|
||||
Ok(Vec::<T>::decode(&mut &vec[..]).expect("Wasm to host values are encoded correctly; qed"))
|
||||
Ok(Vec::<T>::decode(&mut &vec[..])
|
||||
.expect("Wasm to host values are encoded correctly; qed"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,13 +249,11 @@ impl IntoPreallocatedFFIValue for [u8] {
|
||||
let (ptr, len) = unpack_ptr_and_len(allocated);
|
||||
|
||||
if (len as usize) < self_instance.len() {
|
||||
Err(
|
||||
format!(
|
||||
"Preallocated buffer is not big enough (given {} vs needed {})!",
|
||||
len,
|
||||
self_instance.len()
|
||||
)
|
||||
)
|
||||
Err(format!(
|
||||
"Preallocated buffer is not big enough (given {} vs needed {})!",
|
||||
len,
|
||||
self_instance.len()
|
||||
))
|
||||
} else {
|
||||
context.write_memory(Pointer::new(ptr), &self_instance)
|
||||
}
|
||||
@@ -367,7 +367,10 @@ impl<T: codec::Codec> PassBy for Option<T> {
|
||||
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
#[tuple_types_no_default_trait_bound]
|
||||
impl PassBy for Tuple where Self: codec::Codec {
|
||||
impl PassBy for Tuple
|
||||
where
|
||||
Self: codec::Codec,
|
||||
{
|
||||
type PassBy = Codec<Self>;
|
||||
}
|
||||
|
||||
@@ -511,7 +514,8 @@ macro_rules! for_u128_i128 {
|
||||
type SelfInstance = $type;
|
||||
|
||||
fn from_ffi_value(context: &mut dyn FunctionContext, arg: u32) -> Result<$type> {
|
||||
let data = context.read_memory(Pointer::new(arg), mem::size_of::<$type>() as u32)?;
|
||||
let data =
|
||||
context.read_memory(Pointer::new(arg), mem::size_of::<$type>() as u32)?;
|
||||
let mut res = [0u8; mem::size_of::<$type>()];
|
||||
res.copy_from_slice(&data);
|
||||
Ok(<$type>::from_le_bytes(res))
|
||||
@@ -526,7 +530,7 @@ macro_rules! for_u128_i128 {
|
||||
Ok(addr.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
for_u128_i128!(u128);
|
||||
|
||||
@@ -292,28 +292,28 @@ pub use sp_std;
|
||||
/// the case when that would create a circular dependency. You usually _do not_ want to add this
|
||||
/// flag, as tracing doesn't cost you anything by default anyways (it is added as a no-op) but is
|
||||
/// super useful for debugging later.
|
||||
///
|
||||
pub use sp_runtime_interface_proc_macro::runtime_interface;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[cfg(feature = "std")]
|
||||
pub use sp_externalities::{
|
||||
set_and_run_with_externalities, with_externalities, Externalities, ExternalitiesExt, ExtensionStore,
|
||||
set_and_run_with_externalities, with_externalities, ExtensionStore, Externalities,
|
||||
ExternalitiesExt,
|
||||
};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use codec;
|
||||
|
||||
pub(crate) mod impls;
|
||||
#[cfg(feature = "std")]
|
||||
pub mod host;
|
||||
pub(crate) mod impls;
|
||||
pub mod pass_by;
|
||||
#[cfg(any(not(feature = "std"), doc))]
|
||||
pub mod wasm;
|
||||
pub mod pass_by;
|
||||
|
||||
mod util;
|
||||
|
||||
pub use util::{unpack_ptr_and_len, pack_ptr_and_len};
|
||||
pub use util::{pack_ptr_and_len, unpack_ptr_and_len};
|
||||
|
||||
/// Something that can be used by the runtime interface as type to communicate between wasm and the
|
||||
/// host.
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
//!
|
||||
//! [`Codec`], [`Inner`] and [`Enum`] are the provided strategy implementations.
|
||||
|
||||
use crate::{RIType, util::{unpack_ptr_and_len, pack_ptr_and_len}};
|
||||
use crate::{
|
||||
util::{pack_ptr_and_len, unpack_ptr_and_len},
|
||||
RIType,
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use crate::host::*;
|
||||
@@ -30,7 +33,7 @@ use crate::wasm::*;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_wasm_interface::{FunctionContext, Pointer, Result};
|
||||
|
||||
use sp_std::{marker::PhantomData, convert::TryFrom};
|
||||
use sp_std::{convert::TryFrom, marker::PhantomData};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use sp_std::vec::Vec;
|
||||
@@ -119,18 +122,12 @@ pub trait PassByImpl<T>: RIType {
|
||||
/// Convert the given instance to the ffi value.
|
||||
///
|
||||
/// For more information see: [`crate::host::IntoFFIValue::into_ffi_value`]
|
||||
fn into_ffi_value(
|
||||
instance: T,
|
||||
context: &mut dyn FunctionContext,
|
||||
) -> Result<Self::FFIType>;
|
||||
fn into_ffi_value(instance: T, context: &mut dyn FunctionContext) -> Result<Self::FFIType>;
|
||||
|
||||
/// Create `T` from the given ffi value.
|
||||
///
|
||||
/// For more information see: [`crate::host::FromFFIValue::from_ffi_value`]
|
||||
fn from_ffi_value(
|
||||
context: &mut dyn FunctionContext,
|
||||
arg: Self::FFIType,
|
||||
) -> Result<T>;
|
||||
fn from_ffi_value(context: &mut dyn FunctionContext, arg: Self::FFIType) -> Result<T>;
|
||||
}
|
||||
|
||||
/// Something that provides a strategy for passing a type between wasm and the host.
|
||||
@@ -220,10 +217,7 @@ pub struct Codec<T: codec::Codec>(PhantomData<T>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: codec::Codec> PassByImpl<T> for Codec<T> {
|
||||
fn into_ffi_value(
|
||||
instance: T,
|
||||
context: &mut dyn FunctionContext,
|
||||
) -> Result<Self::FFIType> {
|
||||
fn into_ffi_value(instance: T, context: &mut dyn FunctionContext) -> Result<Self::FFIType> {
|
||||
let vec = instance.encode();
|
||||
let ptr = context.allocate_memory(vec.len() as u32)?;
|
||||
context.write_memory(ptr, &vec)?;
|
||||
@@ -231,14 +225,10 @@ impl<T: codec::Codec> PassByImpl<T> for Codec<T> {
|
||||
Ok(pack_ptr_and_len(ptr.into(), vec.len() as u32))
|
||||
}
|
||||
|
||||
fn from_ffi_value(
|
||||
context: &mut dyn FunctionContext,
|
||||
arg: Self::FFIType,
|
||||
) -> Result<T> {
|
||||
fn from_ffi_value(context: &mut dyn FunctionContext, arg: Self::FFIType) -> Result<T> {
|
||||
let (ptr, len) = unpack_ptr_and_len(arg);
|
||||
let vec = context.read_memory(Pointer::new(ptr), len)?;
|
||||
T::decode(&mut &vec[..])
|
||||
.map_err(|e| format!("Could not decode value from wasm: {}", e))
|
||||
T::decode(&mut &vec[..]).map_err(|e| format!("Could not decode value from wasm: {}", e))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,35 +320,31 @@ pub struct Inner<T: PassByInner<Inner = I>, I: RIType>(PhantomData<(T, I)>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: PassByInner<Inner = I>, I: RIType> PassByImpl<T> for Inner<T, I>
|
||||
where I: IntoFFIValue + FromFFIValue<SelfInstance=I>
|
||||
where
|
||||
I: IntoFFIValue + FromFFIValue<SelfInstance = I>,
|
||||
{
|
||||
fn into_ffi_value(
|
||||
instance: T,
|
||||
context: &mut dyn FunctionContext,
|
||||
) -> Result<Self::FFIType> {
|
||||
fn into_ffi_value(instance: T, context: &mut dyn FunctionContext) -> Result<Self::FFIType> {
|
||||
instance.into_inner().into_ffi_value(context)
|
||||
}
|
||||
|
||||
fn from_ffi_value(
|
||||
context: &mut dyn FunctionContext,
|
||||
arg: Self::FFIType,
|
||||
) -> Result<T> {
|
||||
fn from_ffi_value(context: &mut dyn FunctionContext, arg: Self::FFIType) -> Result<T> {
|
||||
I::from_ffi_value(context, arg).map(T::from_inner)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T: PassByInner<Inner = I>, I: RIType> PassByImpl<T> for Inner<T, I>
|
||||
where I: IntoFFIValue + FromFFIValue
|
||||
where
|
||||
I: IntoFFIValue + FromFFIValue,
|
||||
{
|
||||
type Owned = I::Owned;
|
||||
|
||||
fn into_ffi_value(instance: &T) -> WrappedFFIValue<Self::FFIType, Self::Owned> {
|
||||
instance.inner().into_ffi_value()
|
||||
instance.inner().into_ffi_value()
|
||||
}
|
||||
|
||||
fn from_ffi_value(arg: Self::FFIType) -> T {
|
||||
T::from_inner(I::from_ffi_value(arg))
|
||||
T::from_inner(I::from_ffi_value(arg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,17 +401,11 @@ pub struct Enum<T: Copy + Into<u8> + TryFrom<u8>>(PhantomData<T>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Copy + Into<u8> + TryFrom<u8>> PassByImpl<T> for Enum<T> {
|
||||
fn into_ffi_value(
|
||||
instance: T,
|
||||
_: &mut dyn FunctionContext,
|
||||
) -> Result<Self::FFIType> {
|
||||
fn into_ffi_value(instance: T, _: &mut dyn FunctionContext) -> Result<Self::FFIType> {
|
||||
Ok(instance.into())
|
||||
}
|
||||
|
||||
fn from_ffi_value(
|
||||
_: &mut dyn FunctionContext,
|
||||
arg: Self::FFIType,
|
||||
) -> Result<T> {
|
||||
fn from_ffi_value(_: &mut dyn FunctionContext, arg: Self::FFIType) -> Result<T> {
|
||||
T::try_from(arg).map_err(|_| format!("Invalid enum discriminant: {}", arg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ impl<T: Copy> ExchangeableFunction<T> {
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the original implementation wrapped in [`RestoreImplementation`].
|
||||
pub fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation<T> {
|
||||
pub fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation<T> {
|
||||
if let ExchangeableFunctionState::Replaced = self.0.get().1 {
|
||||
panic!("Trying to replace an already replaced implementation!")
|
||||
}
|
||||
@@ -139,6 +139,7 @@ pub struct RestoreImplementation<T: 'static + Copy>(&'static ExchangeableFunctio
|
||||
|
||||
impl<T: Copy> Drop for RestoreImplementation<T> {
|
||||
fn drop(&mut self) {
|
||||
self.0.restore_orig_implementation(self.1.take().expect("Value is only taken on drop; qed"));
|
||||
self.0
|
||||
.restore_orig_implementation(self.1.take().expect("Value is only taken on drop; qed"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user