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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions crates/transcode/src/env_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

decoders: HashMap<u32, Box<dyn CustomTypeDecoder + Send + Sync>>,
}

impl EnvTypesTranscoder {
/// Construct an `EnvTypesTranscoder` from the given type registry.
pub fn new(
encoders: HashMap<u32, Box<dyn CustomTypeEncoder>>,
decoders: HashMap<u32, Box<dyn CustomTypeDecoder>>,
encoders: HashMap<u32, Box<dyn CustomTypeEncoder + Send + Sync>>,
decoders: HashMap<u32, Box<dyn CustomTypeDecoder + Send + Sync>>,
) -> Self {
Self { encoders, decoders }
}
Expand Down
10 changes: 5 additions & 5 deletions crates/transcode/src/transcoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl Transcoder {
/// Construct a [`Transcoder`], allows registering custom transcoders for certain types.
pub struct TranscoderBuilder {
types_by_path: TypesByPath,
encoders: HashMap<u32, Box<dyn CustomTypeEncoder>>,
decoders: HashMap<u32, Box<dyn CustomTypeDecoder>>,
encoders: HashMap<u32, Box<dyn CustomTypeEncoder + Send + Sync>>,
decoders: HashMap<u32, Box<dyn CustomTypeDecoder + Send + Sync>>,
}

impl TranscoderBuilder {
Expand All @@ -106,7 +106,7 @@ impl TranscoderBuilder {
pub fn register_custom_type_transcoder<T, U>(self, transcoder: U) -> Self
where
T: TypeInfo + 'static,
U: CustomTypeEncoder + CustomTypeDecoder + Clone + 'static,
U: CustomTypeEncoder + CustomTypeDecoder + Clone + Send + Sync + 'static,
{
self.register_custom_type_encoder::<T, U>(transcoder.clone())
.register_custom_type_decoder::<T, U>(transcoder)
Expand All @@ -115,7 +115,7 @@ impl TranscoderBuilder {
pub fn register_custom_type_encoder<T, U>(self, encoder: U) -> Self
where
T: TypeInfo + 'static,
U: CustomTypeEncoder + 'static,
U: CustomTypeEncoder + Send + Sync + 'static,
{
let mut this = self;

Expand Down Expand Up @@ -144,7 +144,7 @@ impl TranscoderBuilder {
pub fn register_custom_type_decoder<T, U>(self, encoder: U) -> Self
where
T: TypeInfo + 'static,
U: CustomTypeDecoder + 'static,
U: CustomTypeDecoder + Send + Sync + 'static,
{
let mut this = self;

Expand Down