@@ -11,12 +11,12 @@ use crate::platform::{self, OsIpcChannel, OsIpcReceiver, OsIpcReceiverSet, OsIpc
1111use crate :: platform:: {
1212 OsIpcOneShotServer , OsIpcSelectionResult , OsIpcSharedMemory , OsOpaqueIpcChannel ,
1313} ;
14+ use crate :: { IpcError , TryRecvError } ;
1415
1516use bincode;
1617use serde:: { de:: Error , Deserialize , Deserializer , Serialize , Serializer } ;
1718use std:: cell:: RefCell ;
1819use std:: cmp:: min;
19- use std:: error:: Error as StdError ;
2020use std:: fmt:: { self , Debug , Formatter } ;
2121use std:: io;
2222use std:: marker:: PhantomData ;
@@ -37,57 +37,6 @@ thread_local! {
3737 const { RefCell :: new( Vec :: new( ) ) }
3838}
3939
40- #[ derive( Debug ) ]
41- pub enum IpcError {
42- Bincode ( bincode:: Error ) ,
43- Io ( io:: Error ) ,
44- Disconnected ,
45- }
46-
47- impl fmt:: Display for IpcError {
48- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
49- match * self {
50- IpcError :: Bincode ( ref err) => write ! ( fmt, "bincode error: {err}" ) ,
51- IpcError :: Io ( ref err) => write ! ( fmt, "io error: {err}" ) ,
52- IpcError :: Disconnected => write ! ( fmt, "disconnected" ) ,
53- }
54- }
55- }
56-
57- impl StdError for IpcError {
58- fn source ( & self ) -> Option < & ( dyn StdError + ' static ) > {
59- match * self {
60- IpcError :: Bincode ( ref err) => Some ( err) ,
61- IpcError :: Io ( ref err) => Some ( err) ,
62- IpcError :: Disconnected => None ,
63- }
64- }
65- }
66-
67- #[ derive( Debug ) ]
68- pub enum TryRecvError {
69- IpcError ( IpcError ) ,
70- Empty ,
71- }
72-
73- impl fmt:: Display for TryRecvError {
74- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
75- match * self {
76- TryRecvError :: IpcError ( ref err) => write ! ( fmt, "ipc error: {err}" ) ,
77- TryRecvError :: Empty => write ! ( fmt, "empty" ) ,
78- }
79- }
80- }
81-
82- impl StdError for TryRecvError {
83- fn source ( & self ) -> Option < & ( dyn StdError + ' static ) > {
84- match * self {
85- TryRecvError :: IpcError ( ref err) => Some ( err) ,
86- TryRecvError :: Empty => None ,
87- }
88- }
89- }
90-
9140/// Create a connected [IpcSender] and [IpcReceiver] that
9241/// transfer messages of a given type provided by type `T`
9342/// or inferred by the types of messages sent by the sender.
@@ -248,16 +197,12 @@ where
248197{
249198 /// Blocking receive.
250199 pub fn recv ( & self ) -> Result < T , IpcError > {
251- self . os_receiver . recv ( ) ?. to ( ) . map_err ( IpcError :: Bincode )
200+ self . os_receiver . recv ( ) ?. to ( )
252201 }
253202
254203 /// Non-blocking receive
255204 pub fn try_recv ( & self ) -> Result < T , TryRecvError > {
256- self . os_receiver
257- . try_recv ( ) ?
258- . to ( )
259- . map_err ( IpcError :: Bincode )
260- . map_err ( TryRecvError :: IpcError )
205+ self . os_receiver . try_recv ( ) ?. to ( ) . map_err ( |e| e. into ( ) )
261206 }
262207
263208 /// Blocks for up to the specified duration attempting to receive a message.
@@ -270,8 +215,7 @@ where
270215 self . os_receiver
271216 . try_recv_timeout ( duration) ?
272217 . to ( )
273- . map_err ( IpcError :: Bincode )
274- . map_err ( TryRecvError :: IpcError )
218+ . map_err ( |e| e. into ( ) )
275219 }
276220
277221 /// Erase the type of the channel.
@@ -364,7 +308,7 @@ where
364308 }
365309
366310 /// Send data across the channel to the receiver.
367- pub fn send ( & self , data : T ) -> Result < ( ) , bincode :: Error > {
311+ pub fn send ( & self , data : T ) -> Result < ( ) , IpcError > {
368312 let mut bytes = Vec :: with_capacity ( 4096 ) ;
369313 OS_IPC_CHANNELS_FOR_SERIALIZATION . with ( |os_ipc_channels_for_serialization| {
370314 OS_IPC_SHARED_MEMORY_REGIONS_FOR_SERIALIZATION . with (
@@ -726,7 +670,7 @@ impl IpcMessage {
726670 }
727671
728672 /// Deserialize the raw data in the contained message into the inferred type.
729- pub fn to < T > ( mut self ) -> Result < T , bincode :: Error >
673+ pub fn to < T > ( mut self ) -> Result < T , IpcError >
730674 where
731675 T : for < ' de > Deserialize < ' de > + Serialize ,
732676 {
@@ -744,7 +688,7 @@ impl IpcMessage {
744688 . map ( Some )
745689 . collect ( ) ,
746690 ) ;
747- let result = bincode:: deserialize ( & self . data [ ..] ) ;
691+ let result = bincode:: deserialize ( & self . data [ ..] ) . map_err ( |e| e . into ( ) ) ;
748692 * os_ipc_shared_memory_regions_for_deserialization. borrow_mut ( ) =
749693 old_ipc_shared_memory_regions_for_deserialization;
750694 mem:: swap (
@@ -886,7 +830,7 @@ where
886830 ) )
887831 }
888832
889- pub fn accept ( self ) -> Result < ( IpcReceiver < T > , T ) , bincode :: Error > {
833+ pub fn accept ( self ) -> Result < ( IpcReceiver < T > , T ) , IpcError > {
890834 let ( os_receiver, ipc_message) = self . os_server . accept ( ) ?;
891835 Ok ( (
892836 IpcReceiver {
0 commit comments