Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bounds on Config trait that aren't strictly necessary #389

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate/", branch = "maste
sp-version = { package = "sp-version", git = "https://github.com/paritytech/substrate/", branch = "master" }

frame-metadata = "14.0.0"
derivative = "2.2.0"

[dev-dependencies]
sp-arithmetic = { git = "https://github.com/paritytech/substrate/", branch = "master", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::{
Config,
Metadata,
};
use derivative::Derivative;
use std::sync::Arc;

/// ClientBuilder for constructing a Client.
Expand Down Expand Up @@ -111,7 +112,8 @@ impl ClientBuilder {
}

/// Client to interface with a substrate node.
#[derive(Clone)]
#[derive(Derivative)]
#[derivative(Clone(bound = ""))]
pub struct Client<T: Config> {
rpc: Rpc<T>,
genesis_hash: T::Hash,
Expand Down
10 changes: 7 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ use sp_runtime::traits::{
};

/// Runtime types.
pub trait Config: Clone + Default + Sized + Send + Sync + 'static {
// Note: the 'static bound isn't strictly required, but currently deriving TypeInfo
// automatically applies a 'static bound to all generic types (including this one),
// and so until that is resolved, we'll keep the (easy to satisfy) constraint here.
Comment on lines +35 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't very likely to ever occur I think?

pub trait Config: 'static {
/// Account index (aka nonce) type. This stores the number of previous
/// transactions associated with a sender account.
type Index: Parameter + Member + Default + AtLeast32Bit + Copy + scale_info::TypeInfo;
Expand Down Expand Up @@ -83,8 +86,9 @@ pub trait Parameter: Codec + EncodeLike + Clone + Eq + Debug {}
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + Debug {}

/// Default set of commonly used types by Substrate runtimes.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DefaultConfig;
// Note: We only use this at the type level, so it should be impossible to
// create an instance of it.
pub enum DefaultConfig {}

impl Config for DefaultConfig {
type Index = u32;
Expand Down
32 changes: 15 additions & 17 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use codec::{
Codec,
Compact,
Decode,
Encode,
Error as CodecError,
Input,
};
use std::marker::PhantomData;

use crate::{
metadata::{
EventMetadata,
Expand All @@ -33,8 +23,18 @@ use crate::{
Error,
Event,
Metadata,
PhantomDataSendSync,
Phase,
};
use codec::{
Codec,
Compact,
Decode,
Encode,
Error as CodecError,
Input,
};
use derivative::Derivative;
use scale_info::{
TypeDef,
TypeDefPrimitive,
Expand Down Expand Up @@ -69,16 +69,14 @@ impl RawEvent {
}

/// Events decoder.
#[derive(Debug, Clone)]
pub struct EventsDecoder<T> {
#[derive(Derivative)]
#[derivative(Clone(bound = ""), Debug(bound = ""))]
pub struct EventsDecoder<T: Config> {
metadata: Metadata,
marker: PhantomData<T>,
marker: PhantomDataSendSync<T>,
}

impl<T> EventsDecoder<T>
where
T: Config,
{
impl<T: Config> EventsDecoder<T> {
/// Creates a new `EventsDecoder`.
pub fn new(metadata: Metadata) -> Self {
Self {
Expand Down
Loading