@@ -67,9 +67,15 @@ impl InfoBuilder {
6767
6868type SendFunction = fn ( String , Vec < u8 > ) ;
6969pub type ProcessFunction = fn ( Vec < u8 > ) -> Result < Vec < u8 > , Vec < u8 > > ;
70- pub struct Participant {
71- pub info : Info ,
72- pub process : ProcessFunction ,
70+
71+ pub trait ParticipantTrait {
72+ fn info ( & self ) -> Info ;
73+ // fn process(&self, Vec<u8>) -> Result<Vec<u8>, Vec<u8>>;
74+ }
75+
76+ struct Participant {
77+ info : Info ,
78+ process : ProcessFunction
7379}
7480
7581struct Connection {
@@ -265,13 +271,15 @@ fn parse(options: &mut Options) {
265271// XXX: seems rust-amqp makes program hangs forever if error occurs / channel is borked?
266272// TODO: pass port info in/out of process()
267273// TODO: nicer way to declare ports? ideally they are enums not stringly typed?
268- pub fn main ( orig : Participant ) {
274+ pub fn main ( orig : & ParticipantTrait , func : ProcessFunction ) {
269275
270276 let mut options = Options { .. Default :: default ( ) } ;
271277 parse ( & mut options) ;
272278
273- let info = normalize_info ( & orig. info , & options) ;
274- let p = Participant { info : info, process : orig. process } ; // XXX: hack
279+ let i : Info = orig. info ( ) ;
280+ let info = normalize_info ( & i, & options) ;
281+
282+ let p = Participant { info : info, process : func } ; // XXX: hack
275283
276284 let mut c = start_participant ( & p, & options) ;
277285 println ! ( "{}({}) started" , & p. info. role, & p. info. component) ;
0 commit comments