use dioxus::prelude::*; use serde::{de::DeserializeOwned, Deserializer, Serialize, Serializer}; // We use deref specialization to make it possible to pass either a value that implements pub trait SerializeToRemoteWrapper { fn serialize_to_remote(&self, serializer: S) -> Result; } impl SerializeToRemoteWrapper for &T { fn serialize_to_remote( &self, serializer: S, ) -> Result<::Ok, ::Error> { self.serialize(serializer) } } impl SerializeToRemoteWrapper for &mut &S { fn serialize_to_remote( &self, serializer: S2, ) -> Result<::Ok, ::Error> { (**self).serialize_to_remote(serializer) } } pub trait SerializeToRemote { fn serialize_to_remote(&self, serializer: S) -> Result; } impl SerializeToRemote for UseState { fn serialize_to_remote( &self, serializer: S2, ) -> Result<::Ok, ::Error> { self.current().serialize(serializer) } } // We use deref specialization to make it possible to pass either a value that implements pub trait DeserializeOnRemoteWrapper { type Output; fn deserialize_on_remote<'a, D: Deserializer<'a>>( deserializer: D, ) -> Result; } impl DeserializeOnRemoteWrapper for &T { type Output = T; fn deserialize_on_remote<'a, D: Deserializer<'a>>( deserializer: D, ) -> Result { T::deserialize(deserializer) } } impl DeserializeOnRemoteWrapper for &mut &D { type Output = D::Output; fn deserialize_on_remote<'a, D2: Deserializer<'a>>( deserializer: D2, ) -> Result { D::deserialize_on_remote(deserializer) } } pub trait DeserializeOnRemote { type Output; fn deserialize_on_remote<'a, D: Deserializer<'a>>( deserializer: D, ) -> Result; } impl DeserializeOnRemote for UseState { type Output = D; fn deserialize_on_remote<'a, D2: Deserializer<'a>>( deserializer: D2, ) -> Result { D::deserialize(deserializer) } }