@@ -66,7 +66,7 @@ pub struct Machine<C, E> {
6666impl < C , E > Machine < C , E >
6767where
6868 C : Display + Send + ' static ,
69- E : FromStr + Send + ' static ,
69+ E : FromStr + Display + Send + ' static ,
7070 E :: Err : std:: fmt:: Debug + Display + Send + Sync ,
7171{
7272 pub async fn new ( id : MachineId , plug : Plug , cmd : Command ) -> Self {
@@ -138,24 +138,12 @@ impl<C, E> Machine<C, E> {
138138 pub fn namespace ( & self ) -> Namespace {
139139 self . ns
140140 }
141- }
142-
143- impl < C , E : Display > Machine < C , E > {
144- async fn do_recv ( & mut self ) -> Option < E > {
145- let ev = self . rx . next ( ) . await ;
146- if let Some ( ref ev) = ev {
147- log:: info!( "{} {}" , self . id, ev) ;
148- } else {
149- log:: info!( "{} event stream closed" , self . id) ;
150- }
151- ev
152- }
153141
154142 pub async fn recv ( & mut self ) -> Option < E > {
155143 if let Some ( ev) = self . buffer . pop_front ( ) {
156144 Some ( ev)
157145 } else {
158- self . do_recv ( ) . await
146+ self . rx . next ( ) . await
159147 }
160148 }
161149
@@ -173,7 +161,7 @@ impl<C, E: Display> Machine<C, E> {
173161 return Some ( res) ;
174162 }
175163 loop {
176- match self . do_recv ( ) . await {
164+ match self . rx . next ( ) . await {
177165 Some ( ev) => {
178166 if let Some ( res) = f ( & ev) {
179167 return Some ( res) ;
@@ -196,7 +184,7 @@ impl<C, E: Display> Machine<C, E> {
196184 }
197185 }
198186 loop {
199- match self . do_recv ( ) . await {
187+ match self . rx . next ( ) . await {
200188 Some ( ev) => {
201189 if let Some ( res) = f ( & ev) {
202190 return Some ( res) ;
@@ -227,7 +215,7 @@ fn machine<C, E>(
227215) -> thread:: JoinHandle < Result < ( ) > >
228216where
229217 C : Display + Send + ' static ,
230- E : FromStr + Send + ' static ,
218+ E : FromStr + Display + Send + ' static ,
231219 E :: Err : std:: fmt:: Debug + Display + Send + Sync ,
232220{
233221 thread:: spawn ( move || {
@@ -333,6 +321,7 @@ where
333321 Ok ( ev) => ev,
334322 Err ( err) => return Err ( Error :: new ( ErrorKind :: Other , err. to_string ( ) ) ) ,
335323 } ;
324+ log:: debug!( "{} {}" , id, ev) ;
336325 if event. unbounded_send ( ev) . is_err ( ) {
337326 break ;
338327 }
0 commit comments