Answering my own question here, but I had an issue where I had a shared Rust library (entropy-shared
) with types that were shared between a Rust binary using subxt
and some Substrate pallets it interacts with. The library also included all the impls
on the types, too, but I couldn't use them because:
subxt
wouldn't let me use my library types directly (egentropy_shared::Constraints
); it wanted me to use the reexported types from thesubxt
macro, but,- there were no
impls
on the reexported types. I couldn't even transcode the two types between each other, since they're all generated from the Substrate metadata.
My errors were as follows:
error[E0308]: mismatched types
--> crypto/server/src/helpers/substrate.rs:153:9
|
151 | let update_constraints_tx = entropy::tx().constraints().update_constraints(
| ------------------ arguments to this function are incorrect
152 | sig_req_keyring.to_account_id(),
153 | initial_constraints,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `entropy_shared::constraints::Constraints`, found struct `entropy_shared::Constraints`
|
= note: struct `entropy_shared::Constraints` and struct `entropy_shared::constraints::Constraints` have similar names, but are actually distinct types
note: struct `entropy_shared::Constraints` is defined in crate `entropy_shared`
--> /Users/jake/codebases/entropy/entropy-core/crypto/shared/src/constraints.rs:19:1
|
19 | pub struct Constraints {
| ^^^^^^^^^^^^^^^^^^^^^^
note: struct `entropy_shared::constraints::Constraints` is defined in the current crate
--> crypto/server/src/chain_api.rs:5:1
|
5 | #[subxt::subxt(runtime_metadata_path = "entropy_metadata.scale")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: associated function defined here
--> crypto/server/src/chain_api.rs:5:1
|
5 | #[subxt::subxt(runtime_metadata_path = "entropy_metadata.scale")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the attribute macro `subxt::subxt` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0308`.
warning: `server` (bin "server" test) generated 1 warning
error: could not compile `server` due to previous error; 1 warning emitted