Remove bounds on Config trait that aren't strictly necessary #389
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use types implementing the
Config
trait in Subxt, but only at compile-time; we never instantiate an instance of them. And yet, the Config trait has various bounds on it (Debug
,Clone
,Copy
,Send
,Sync
etc).This PR removes those bounds (well, mostly;
'static
is still there for now and should be able to go away eventually, but that should never complicate anything in real use).The reason I think that these bounds existed in the first place is that Rust's inbuilt "derive" mechanism is quite primitive (eg deriving
Clone
will derive something likeimpl <T: Clone> Clone for MyType<T>
; theT
also needs to beClone
). As a result, we ended up with a bunch of additional bounds on theConfig
type so that it could be passed around as a generic typeT
and would still satisfy these derives.Removing the bounds on Config has pros and cons:
Pros:
Config
is never instantiated, and so it shouldn't need any of these bounds.Config
on their own types; they don't need to pointlessly derive anything.Cons:
derivative
crate to allow ignoring theT
when deriving various traits on things that useConfig
. (we could manually derive the traits everywhere, but that would be needlessly verbose). This additional complexity will apply to anything else that takes aT: Config
type.PhantomDataSendSync<T>
type (which is justPhantomData + Send + Sync
) to ensure that the lack ofSend
+Sync
onConfig
doesn't translate to a lack ofSend
+Sync
on types using the config.I think I lean towards being more "correct" at the cost of the additional complexity (and from a user facing POV, they won't see any of the added complexity, but will benefit a little from
Config
being easier to implement.That said, I'm curious to hear people's opinions on the matter!