mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 04:47:56 +00:00
subxt: Derive std::cmp traits for subxt payloads and addresses (#1429)
* subxt/tx: Derive std::cmp traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/runtime_api: Derive std::cmp traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/constants: Derive std::cmp traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/custom_values: Derive std::cmp traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/storage: Derive std::cmp traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Fix non_canonical_partial_ord_impl clippy introduced in 1.73 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Add comment wrt derivative issue that triggers clippy warning Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update subxt/src/backend/mod.rs * Update subxt/src/constants/constant_address.rs --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -184,6 +184,7 @@ impl<H: PartialEq> PartialEq for BlockRef<H> {
|
||||
}
|
||||
impl<H: Eq> Eq for BlockRef<H> {}
|
||||
|
||||
// Manual implementation to work around https://github.com/mcarton/rust-derivative/issues/115.
|
||||
impl<H: PartialOrd> PartialOrd for BlockRef<H> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.hash.partial_cmp(&other.hash)
|
||||
|
||||
@@ -28,7 +28,13 @@ pub trait ConstantAddress {
|
||||
|
||||
/// This represents the address of a constant.
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Clone(bound = ""), Debug(bound = ""))]
|
||||
#[derivative(
|
||||
Clone(bound = ""),
|
||||
Debug(bound = ""),
|
||||
Eq(bound = ""),
|
||||
Ord(bound = ""),
|
||||
PartialEq(bound = "")
|
||||
)]
|
||||
pub struct Address<ReturnTy> {
|
||||
pallet_name: Cow<'static, str>,
|
||||
constant_name: Cow<'static, str>,
|
||||
@@ -36,6 +42,13 @@ pub struct Address<ReturnTy> {
|
||||
_marker: std::marker::PhantomData<ReturnTy>,
|
||||
}
|
||||
|
||||
// Manual implementation to work around https://github.com/mcarton/rust-derivative/issues/115.
|
||||
impl<ReturnTy> PartialOrd for Address<ReturnTy> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of address typically used to return dynamic constant values.
|
||||
pub type DynamicAddress = Address<DecodedValueThunk>;
|
||||
|
||||
|
||||
@@ -38,13 +38,25 @@ pub struct Yes;
|
||||
|
||||
/// A static address to a custom value.
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Clone(bound = ""), Debug(bound = ""))]
|
||||
#[derivative(
|
||||
Clone(bound = ""),
|
||||
Debug(bound = ""),
|
||||
Eq(bound = ""),
|
||||
Ord(bound = ""),
|
||||
PartialEq(bound = "")
|
||||
)]
|
||||
pub struct StaticAddress<ReturnTy, IsDecodable> {
|
||||
name: &'static str,
|
||||
hash: Option<[u8; 32]>,
|
||||
phantom: PhantomData<(ReturnTy, IsDecodable)>,
|
||||
}
|
||||
|
||||
impl<ReturnTy, IsDecodable> PartialOrd for StaticAddress<ReturnTy, IsDecodable> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<ReturnTy, IsDecodable> StaticAddress<ReturnTy, IsDecodable> {
|
||||
#[doc(hidden)]
|
||||
/// Creates a new StaticAddress.
|
||||
|
||||
@@ -69,7 +69,11 @@ pub trait RuntimeApiPayload {
|
||||
#[derive(Derivative)]
|
||||
#[derivative(
|
||||
Clone(bound = "ArgsData: Clone"),
|
||||
Debug(bound = "ArgsData: std::fmt::Debug")
|
||||
Debug(bound = "ArgsData: std::fmt::Debug"),
|
||||
Eq(bound = "ArgsData: std::cmp::Eq"),
|
||||
Ord(bound = "ArgsData: std::cmp::Ord"),
|
||||
PartialEq(bound = "ArgsData: std::cmp::PartialEq"),
|
||||
PartialOrd(bound = "ArgsData: std::cmp::PartialOrd")
|
||||
)]
|
||||
pub struct Payload<ArgsData, ReturnTy> {
|
||||
trait_name: Cow<'static, str>,
|
||||
|
||||
@@ -55,7 +55,11 @@ pub struct Yes;
|
||||
#[derive(Derivative)]
|
||||
#[derivative(
|
||||
Clone(bound = "StorageKey: Clone"),
|
||||
Debug(bound = "StorageKey: std::fmt::Debug")
|
||||
Debug(bound = "StorageKey: std::fmt::Debug"),
|
||||
Eq(bound = "StorageKey: std::cmp::Eq"),
|
||||
Ord(bound = "StorageKey: std::cmp::Ord"),
|
||||
PartialEq(bound = "StorageKey: std::cmp::PartialEq"),
|
||||
PartialOrd(bound = "StorageKey: std::cmp::PartialOrd")
|
||||
)]
|
||||
pub struct Address<StorageKey, ReturnTy, Fetchable, Defaultable, Iterable> {
|
||||
pallet_name: Cow<'static, str>,
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
metadata::Metadata,
|
||||
};
|
||||
use codec::Encode;
|
||||
use derivative::Derivative;
|
||||
use scale_encode::EncodeAsFields;
|
||||
use scale_value::{Composite, ValueDef, Variant};
|
||||
use std::{borrow::Cow, sync::Arc};
|
||||
@@ -48,7 +49,15 @@ pub struct ValidationDetails<'a> {
|
||||
}
|
||||
|
||||
/// A transaction payload containing some generic `CallData`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Derivative)]
|
||||
#[derivative(
|
||||
Clone(bound = "CallData: Clone"),
|
||||
Debug(bound = "CallData: std::fmt::Debug"),
|
||||
Eq(bound = "CallData: std::cmp::Eq"),
|
||||
Ord(bound = "CallData: std::cmp::Ord"),
|
||||
PartialEq(bound = "CallData: std::cmp::PartialEq"),
|
||||
PartialOrd(bound = "CallData: std::cmp::PartialOrd")
|
||||
)]
|
||||
pub struct Payload<CallData> {
|
||||
pallet_name: Cow<'static, str>,
|
||||
call_name: Cow<'static, str>,
|
||||
|
||||
Reference in New Issue
Block a user