Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(warnings)]
- extern crate futures;
- extern crate tokio;
- extern crate syn;
- use futures::{Future, Poll, Async, task};
- use futures::lazy;
- use futures::sync::mpsc::{Receiver, Sender, channel};
- use futures::stream::Stream;
- use futures::sink::Sink;
- use tokio::runtime::Runtime;
- use futures::task::Task;
- use syn::export::fmt::Display;
- use std::marker::PhantomData;
- pub struct CountLogger<U: Send + 'static> {
- count: u32,
- phantom: U
- }
- #[derive_aktor::derive_actor]
- impl<U: Send + 'static> CountLogger<U> {
- pub fn count(&mut self) {
- self.count += 1;
- println!("[COUNT] - {}", self.count);
- }
- }
- pub struct PrintLogger<Z: Send + 'static> {
- z: Z
- }
- #[derive_aktor::derive_actor]
- impl<Z: Send + 'static> PrintLogger<Z> {
- pub fn foo<T: Display + Send + 'static, U: Send + 'static>(&self, bar: T, baz: U, counter: CountLoggerActor) {
- println!("bar {}", bar);
- counter.count();
- }
- }
- fn main() {
- let mut rt: Runtime = Runtime::new().unwrap();
- rt.spawn(lazy(|| -> Result<(), ()> {
- let log_actor = PrintLoggerActor::new(PrintLogger {z: 10});
- let count_actor = CountLoggerActor::new(CountLogger {count: 0, phantom: 5});
- for i in 0..10 {
- log_actor.foo(i, "bar" , count_actor.clone());
- }
- Ok(())
- }));
- rt.shutdown_on_idle().wait().unwrap();
- }
- //fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement