Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #![allow(warnings)]
  2. extern crate futures;
  3. extern crate tokio;
  4. extern crate syn;
  5.  
  6. use futures::{Future, Poll, Async, task};
  7. use futures::lazy;
  8. use futures::sync::mpsc::{Receiver, Sender, channel};
  9. use futures::stream::Stream;
  10. use futures::sink::Sink;
  11. use tokio::runtime::Runtime;
  12. use futures::task::Task;
  13. use syn::export::fmt::Display;
  14.  
  15. use std::marker::PhantomData;
  16.  
  17. pub struct CountLogger<U: Send + 'static> {
  18. count: u32,
  19. phantom: U
  20. }
  21.  
  22. #[derive_aktor::derive_actor]
  23. impl<U: Send + 'static> CountLogger<U> {
  24. pub fn count(&mut self) {
  25. self.count += 1;
  26. println!("[COUNT] - {}", self.count);
  27. }
  28. }
  29.  
  30.  
  31. pub struct PrintLogger<Z: Send + 'static> {
  32. z: Z
  33. }
  34.  
  35. #[derive_aktor::derive_actor]
  36. impl<Z: Send + 'static> PrintLogger<Z> {
  37. pub fn foo<T: Display + Send + 'static, U: Send + 'static>(&self, bar: T, baz: U, counter: CountLoggerActor) {
  38. println!("bar {}", bar);
  39. counter.count();
  40. }
  41. }
  42.  
  43. fn main() {
  44. let mut rt: Runtime = Runtime::new().unwrap();
  45.  
  46. rt.spawn(lazy(|| -> Result<(), ()> {
  47. let log_actor = PrintLoggerActor::new(PrintLogger {z: 10});
  48. let count_actor = CountLoggerActor::new(CountLogger {count: 0, phantom: 5});
  49.  
  50. for i in 0..10 {
  51. log_actor.foo(i, "bar" , count_actor.clone());
  52. }
  53.  
  54. Ok(())
  55. }));
  56.  
  57. rt.shutdown_on_idle().wait().unwrap();
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. //fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement