Skip to content

Commit

Permalink
Remove Send + Sync bound from WireFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Feb 10, 2025
1 parent 68d70f8 commit c13c5bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed the RNG parameter from `Round::receive_message()` and `Session::process_message()`. ([#83])
- Renamed `Round::entry_round()` to `entry_round_id()` and made it mandatory to implement. ([#84])
- Rework `RequiredMessageParts` API. ([#85])
- Removed `Send + Sync` bound on `WireFormat`. ([#92])


### Added
Expand Down Expand Up @@ -58,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#88]: https://github.com/entropyxyz/manul/pull/88
[#90]: https://github.com/entropyxyz/manul/pull/90
[#91]: https://github.com/entropyxyz/manul/pull/91
[#92]: https://github.com/entropyxyz/manul/pull/92


## [0.1.0] - 2024-11-19
Expand Down
8 changes: 5 additions & 3 deletions manul/src/protocol/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ trait ObjectSafeSerializer: Debug {
fn serialize(&self, value: Box<dyn erased_serde::Serialize>) -> Result<Box<[u8]>, LocalError>;
}

// `fn(F)` makes the type `Send` + `Sync` even if `F` isn't.
#[derive(Debug)]
struct SerializerWrapper<F: WireFormat>(PhantomData<F>);
struct SerializerWrapper<F: WireFormat>(PhantomData<fn(F)>);

impl<F: WireFormat> ObjectSafeSerializer for SerializerWrapper<F> {
fn serialize(&self, value: Box<dyn erased_serde::Serialize>) -> Result<Box<[u8]>, LocalError> {
Expand Down Expand Up @@ -42,8 +43,9 @@ impl Serializer {

// Deserialization

// `fn(F)` makes the type `Send` + `Sync` even if `F` isn't.
#[derive(Debug)]
struct DeserializerFactoryWrapper<F>(PhantomData<F>);
struct DeserializerFactoryWrapper<F>(PhantomData<fn(F)>);

trait ObjectSafeDeserializerFactory: Debug {
fn make_erased_deserializer<'de>(&self, bytes: &'de [u8]) -> Box<dyn erased_serde::Deserializer<'de> + 'de>;
Expand All @@ -68,7 +70,7 @@ impl Deserializer {
where
F: WireFormat,
{
Self(Box::new(DeserializerFactoryWrapper(PhantomData::<F>)))
Self(Box::new(DeserializerFactoryWrapper::<F>(PhantomData)))
}

/// Deserializes a `serde`-deserializable object.
Expand Down
2 changes: 1 addition & 1 deletion manul/src/session/wire_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if we could instead type-erase the serializer, we wouldn't need that.
*/

/// A (de)serializer that will be used for the protocol messages.
pub trait WireFormat: 'static + Send + Sync + Debug {
pub trait WireFormat: 'static + Debug {
/// Serializes the given object into a bytestring.
fn serialize<T: Serialize>(value: T) -> Result<Box<[u8]>, LocalError>;

Expand Down

0 comments on commit c13c5bf

Please sign in to comment.