/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use serde::{Deserialize, Serialize}; use serde::{Deserializer, Serializer}; use std::sync::mpsc; macro_rules! unreachable_serializable { ($name:ident) => { impl Serialize for $name { fn serialize(&self, _: S) -> Result { unreachable!(); } } impl<'a, T> Deserialize<'a> for $name { fn deserialize(_: D) -> Result<$name, D::Error> where D: Deserializer<'a>, { unreachable!(); } } }; } pub struct GLPlayerSender(mpsc::Sender); pub struct GLPlayerReceiver(mpsc::Receiver); impl Clone for GLPlayerSender { fn clone(&self) -> Self { GLPlayerSender(self.0.clone()) } } impl GLPlayerSender { #[inline] pub fn send(&self, data: T) -> Result<(), mpsc::SendError> { self.0.send(data) } } impl GLPlayerReceiver { #[inline] pub fn recv(&self) -> Result { self.0.recv() } } pub fn glplayer_channel() -> Result<(GLPlayerSender, GLPlayerReceiver), ()> { let (sender, receiver) = mpsc::channel(); Ok((GLPlayerSender(sender), GLPlayerReceiver(receiver))) } unreachable_serializable!(GLPlayerReceiver); unreachable_serializable!(GLPlayerSender);