AZ
Size: a a a
AZ
AZ
AZ
A
AZ
A
OA
OA
OA
MB
MB
DF
MB
pub struct MyActor {
pub handler: Box<dyn Fn() -> Pin<Box<dyn Future<Output = ()>>> + Send + Unpin + 'static>,,
}
fn handler() -> Pin<Box<dyn Future<Output = ()>>> {
Box::pin(async {})
}pub trait Factory<T, R>: Clone + Unpin + 'static
where
T: Unpin + 'static,
R: Future<Output = ()>,
{
fn call(&self, param: T) -> R;
}
impl<F, R> Factory<(), R> for F
where
F: Fn() -> R + Clone + Unpin + 'static,
R: Future<Output = ()>,
{
fn call(&self, _: ()) -> R {
(self)()
}
}
pub struct Handler<F, T, R>
where
T: Unpin + 'static,
F: Factory<T, R>,
R: Future<Output = ()>,
{
pub hnd: F,
_t: PhantomData<(T, R)>,
}
pub struct MyActor<F, T, R>
where
F: Factory<T, R>,
T: Unpin + 'static,
R: Future<Output = ()> + Unpin + 'static,
{
pub handler: Handler<F, T, R>,
}
async fn handler() {
//...
}
MB
error[E0277]: `from_generator::GenFuture<[static generator@src/main.rs:97:20: 99:2 {}]>` cannot be unpinned
--> src/main.rs:91:18
|
91 | let actor0 = MyActor::new(handler).start();
| ^^^^^^^^^^^^ within `impl futures::Future`, the trait `Unpin` is not implemented for `from_generator::GenFuture<[static generator@src/main.rs:97:20: 99:2 {}]>`
...
97 | async fn handler() {
| - within this `impl futures::Future`
|
::: src/async_handler_type/actor/mod.rs:31:5
|
31 | pub fn new(handler: F) -> Self {
| ------------------------------ required by `MyActor::<F, T, R>::new`
|
= note: required because it appears within the type `impl futures::Future`
= note: required because it appears within the type `impl futures::Future`YM
error[E0277]: `from_generator::GenFuture<[static generator@src/main.rs:97:20: 99:2 {}]>` cannot be unpinned
--> src/main.rs:91:18
|
91 | let actor0 = MyActor::new(handler).start();
| ^^^^^^^^^^^^ within `impl futures::Future`, the trait `Unpin` is not implemented for `from_generator::GenFuture<[static generator@src/main.rs:97:20: 99:2 {}]>`
...
97 | async fn handler() {
| - within this `impl futures::Future`
|
::: src/async_handler_type/actor/mod.rs:31:5
|
31 | pub fn new(handler: F) -> Self {
| ------------------------------ required by `MyActor::<F, T, R>::new`
|
= note: required because it appears within the type `impl futures::Future`
= note: required because it appears within the type `impl futures::Future`YM
MB
pub trait Factory<T, R>: Clone + Unpin + 'static
MB
pub struct Handler<F>Так тоже работает
where F: Future<Output = ()>,
{
pub handler: Box<dyn Fn() -> F>,
}
pub struct MyActor<F>
where F: Future<Output = ()> + 'static,
{
pub handler: Handler<F>,
}
MB
r