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

Require env_type transcoders to be Send + Sync #879

Merged
merged 3 commits into from
Jan 5, 2023

Conversation

obrok
Copy link
Contributor

@obrok obrok commented Dec 21, 2022

They are already required to be 'static, so this seems like a reasonable requirement. In practice, it seems only AccountId and Hash transcoders are inserted into this collection. Adding these two traits allows a ContractMetadataTranscoder to be shared between threads via an Arc. This is very useful, especially given a ContractMetadataTranscoder is not even Clone, which makes it unwieldy to load the metadata once and use it around the program.

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Dec 21, 2022

User @obrok, please sign the CLA here.

They are already required to be 'static, so this seems like a reasonable
requirement. In practice, it seems only `AccountId` and `Hash`
transcoders are inserted into this collection. Adding these two traits
allows a `ContractMetadataTranscoder` to be shared between threads via
an `Arc`.  This is very useful, especially given a
`ContractMetadataTranscoder` is not even `Clone`, which makes it
unwieldy to load the metadata once and use it around the program.
@@ -45,15 +45,15 @@ use std::{
/// Provides custom encoding and decoding for predefined environment types.
#[derive(Default)]
pub struct EnvTypesTranscoder {
encoders: HashMap<u32, Box<dyn CustomTypeEncoder>>,
decoders: HashMap<u32, Box<dyn CustomTypeDecoder>>,
encoders: HashMap<u32, Box<dyn CustomTypeEncoder + Send + Sync>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it also work if we added those constraints to the trait itself e.g. CustomTyoeEncoder: Send + Sync?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that works as well, updated the PR.

@ascjones ascjones merged commit 7ca8c36 into use-ink:master Jan 5, 2023
@ascjones ascjones mentioned this pull request Jan 9, 2023
@ascjones ascjones mentioned this pull request Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants