33
44use alloc:: boxed:: Box ;
55use alloc:: sync:: Arc ;
6- use core:: fmt:: Display ;
6+ use core:: fmt:: { Debug , Display } ;
77use core:: marker:: PhantomData ;
88
99use crate :: { DynMessage , Message , NoElement , View , ViewId , ViewPathTracker } ;
@@ -47,9 +47,18 @@ pub trait RawProxy<Message = DynMessage>: Send + Sync + 'static {
4747 //
4848 // e.g. an `Option<Arc<dyn FnMut(ProxyError, ProxyMessageId?)>>`?
4949 fn send_message ( & self , path : Arc < [ ViewId ] > , message : Message ) -> Result < ( ) , ProxyError > ;
50+ /// Get the debug formatter for this proxy type.
51+ fn dyn_debug ( & self ) -> & dyn Debug ;
52+ }
53+
54+ impl < Message : ' static > Debug for dyn RawProxy < Message > {
55+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
56+ self . dyn_debug ( ) . fmt ( f)
57+ }
5058}
5159
5260/// A way to send a message of an expected type to a specific view.
61+ #[ derive( Debug ) ]
5362pub struct MessageProxy < M : Message > {
5463 proxy : Arc < dyn RawProxy < DynMessage > > ,
5564 path : Arc < [ ViewId ] > ,
@@ -109,10 +118,8 @@ pub enum ProxyError {
109118 ///
110119 /// This likely requires async error handling to happen.
111120 ViewExpired ( DynMessage , Arc < [ ViewId ] > ) ,
112- #[ allow( missing_docs) ]
113- Other ( & ' static str ) ,
114- // TODO: When core::error::Error is stabilised
115- // Other(Box<dyn core::error::Error + Send>),
121+ /// An error specific to the driver being used.
122+ Other ( Box < dyn core:: error:: Error + Send > ) ,
116123}
117124
118125// Is it fine to use thiserror in this crate?
@@ -123,17 +130,16 @@ impl Display for ProxyError {
123130 ProxyError :: ViewExpired ( _, _) => {
124131 f. write_fmt ( format_args ! ( "the corresponding view is no longer present" ) )
125132 }
126-
127- ProxyError :: Other ( inner) => inner. fmt ( f) ,
133+ ProxyError :: Other ( inner) => Display :: fmt ( inner, f) ,
128134 }
129135 }
130136}
131137
132- // impl std ::error::Error for ProxyError {
133- // fn source(&self) -> Option<&(dyn std ::error::Error + 'static)> {
134- // match self {
135- // ProxyError::Other(inner) => inner.source(),
136- // _ => None,
137- // }
138- // }
139- // }
138+ impl core :: error:: Error for ProxyError {
139+ fn source ( & self ) -> Option < & ( dyn core :: error:: Error + ' static ) > {
140+ match self {
141+ ProxyError :: Other ( inner) => inner. source ( ) ,
142+ _ => None ,
143+ }
144+ }
145+ }
0 commit comments