哈尔滨网站设计联系方式,韶关公司做网站,产品网络营销方案,网站怎么做可以增加点击率模拟常用的几种函数调用CallBack的写法。测试调用都放在函数t6_call_back_task中。我正在学习Rust#xff0c;有不对或者欠缺的地方#xff0c;欢迎交流指正
type Callback std::sync::Arcdyn Fn() Send Sync;
type CallbackReturnVal std::sync::Arcdyn Fn…模拟常用的几种函数调用CallBack的写法。测试调用都放在函数t6_call_back_task中。我正在学习Rust有不对或者欠缺的地方欢迎交流指正
type Callback std::sync::Arcdyn Fn() Send Sync;
type CallbackReturnVal std::sync::Arcdyn Fn() - ResultString, i32 Send Sync;
type CallbackResult std::sync::Arcdyn Fn(ResultString, i32) Send Sync;pub(crate) trait EventListener {fn on_action1(self, code: i32);fn on_action2(self, val: String, code: i32);
}pub(crate) struct Executor {call_back: fn(),call_back2: core::option::OptionCallback,call_back3: core::option::OptionCallbackReturnVal,call_back4: core::option::OptionCallbackResult,listener: Boxdyn EventListener static,
}struct DefaultEventListener;impl EventListener for DefaultEventListener {fn on_action1(self, code: i32) {}fn on_action2(self, val: String, code: i32) {}
}impl Executor {pub fn new() - Self {let default_callback: fn() || {println!(Default callback executed);};Executor {call_back: default_callback,call_back2: None,call_back3: None,call_back4: None,listener: Box::new(DefaultEventListener {}),}}pub fn set_call_back(mut self, cb: fn()) {self.call_back cb;}pub fn set_call_back2CB(mut self, call_back: CB)where CB: Fn() Send Sync static {self.call_back2 Some(std::sync::Arc::new(call_back));}pub fn set_call_back3CB(mut self, call_back: CB)where CB: Fn() - ResultString, i32 Send Sync static {self.call_back3 Some(std::sync::Arc::new(call_back));}pub fn set_call_back4CB(mut self, call_back: CB)where CB: Fn(ResultString, i32) Send Sync static {self.call_back4 Some(std::sync::Arc::new(call_back));}pub fn set_call_back5(mut self, listener: Boxdyn EventListener static) {self.listener listener;}pub fn process_events(self) {(self.call_back)();//call_back2if let Some(call_back2_type) self.call_back2 {call_back2_type();call_back2_type();} else {println!(No callback2 to execute.);}//call_back3if let Some(call_back3_type) self.call_back3 {let result call_back3_type();} else {println!(No callback3 to execute.);}//call_back4if let Some(call_back4_type) self.call_back4 {let ok: ResultString, i32 Result::Ok(success.to_string());let error_code: ResultString, i32 Result::Err(-10);call_back4_type(ok);} else {println!(No callback4 to execute.);}//call_back5self.listener.on_action1(1);self.listener.on_action2(.to_string(), -1);}
}pub(crate) struct EventListenerImpl {}impl EventListener for EventListenerImpl {fn on_action1(self, code: i32) {println!(-------on_action1--------code: {}, code);}fn on_action2(self, val: String, code: i32) {println!(-------on_action2--------code: {} , val: {}, code, val);}
}pub(crate) fn t6_call_back_task() {let mut executor Executor::new();executor.set_call_back(|| {println!(-------call_back----1----);});executor.set_call_back2(|| {println!(-------call_back----2----);});executor.set_call_back3(|| {println!(-------call_back----3---);Ok(Callback executed successfully!.to_string())});executor.set_call_back4(|result: ResultString, i32| {println!(-------call_back----4----result: {:?}, result);});let event_listener Box::new(EventListenerImpl {});executor.set_call_back5(event_listener);executor.process_events();
} 文章转载自: http://www.morning.gqwpl.cn.gov.cn.gqwpl.cn http://www.morning.nzqqd.cn.gov.cn.nzqqd.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.wjlhp.cn.gov.cn.wjlhp.cn http://www.morning.tkrwm.cn.gov.cn.tkrwm.cn http://www.morning.ltqtp.cn.gov.cn.ltqtp.cn http://www.morning.dzpnl.cn.gov.cn.dzpnl.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.rhdqz.cn.gov.cn.rhdqz.cn http://www.morning.fkwp.cn.gov.cn.fkwp.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.rwwdp.cn.gov.cn.rwwdp.cn http://www.morning.qzqjz.cn.gov.cn.qzqjz.cn http://www.morning.jmspy.cn.gov.cn.jmspy.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.bqmsm.cn.gov.cn.bqmsm.cn http://www.morning.yqpck.cn.gov.cn.yqpck.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.snyqb.cn.gov.cn.snyqb.cn http://www.morning.jcnmy.cn.gov.cn.jcnmy.cn http://www.morning.mqldj.cn.gov.cn.mqldj.cn http://www.morning.srgsb.cn.gov.cn.srgsb.cn http://www.morning.cwknc.cn.gov.cn.cwknc.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn http://www.morning.jlboyuan.cn.gov.cn.jlboyuan.cn http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn http://www.morning.yrmpr.cn.gov.cn.yrmpr.cn http://www.morning.mlpch.cn.gov.cn.mlpch.cn http://www.morning.shnqh.cn.gov.cn.shnqh.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.cbnlg.cn.gov.cn.cbnlg.cn http://www.morning.gbsby.cn.gov.cn.gbsby.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.cbchz.cn.gov.cn.cbchz.cn http://www.morning.hhfwj.cn.gov.cn.hhfwj.cn http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.cklld.cn.gov.cn.cklld.cn http://www.morning.bqmdl.cn.gov.cn.bqmdl.cn http://www.morning.mgwpy.cn.gov.cn.mgwpy.cn http://www.morning.pmghz.cn.gov.cn.pmghz.cn http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn http://www.morning.dbrnl.cn.gov.cn.dbrnl.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.qswws.cn.gov.cn.qswws.cn http://www.morning.btpll.cn.gov.cn.btpll.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.hyryq.cn.gov.cn.hyryq.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.nkhdt.cn.gov.cn.nkhdt.cn http://www.morning.jlxld.cn.gov.cn.jlxld.cn http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.qwfq.cn.gov.cn.qwfq.cn http://www.morning.24vy.com.gov.cn.24vy.com http://www.morning.gmwdl.cn.gov.cn.gmwdl.cn http://www.morning.rgrz.cn.gov.cn.rgrz.cn http://www.morning.hkpn.cn.gov.cn.hkpn.cn http://www.morning.jcrfm.cn.gov.cn.jcrfm.cn http://www.morning.mnbcj.cn.gov.cn.mnbcj.cn http://www.morning.ghjln.cn.gov.cn.ghjln.cn http://www.morning.zmnyj.cn.gov.cn.zmnyj.cn http://www.morning.njftk.cn.gov.cn.njftk.cn http://www.morning.plxhq.cn.gov.cn.plxhq.cn http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn http://www.morning.slwfy.cn.gov.cn.slwfy.cn http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn http://www.morning.rntyn.cn.gov.cn.rntyn.cn http://www.morning.prhqn.cn.gov.cn.prhqn.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn