async_executors/iface/
local_spawn_handle.rs1#[ allow(unused_imports) ]
2use
4{
5 futures_task :: { SpawnError, LocalFutureObj } ,
6 futures_util :: { task::{ LocalSpawnExt }, future::{ FutureExt, abortable } } ,
7 crate :: { JoinHandle } ,
8 std :: { pin::Pin, future::Future, sync::{ Arc, atomic::AtomicBool }, rc::Rc } ,
9 blanket :: { blanket } ,
10};
11
12
13#[ blanket(derive( Ref, Mut, Box, Arc, Rc )) ]
17pub trait LocalSpawnHandle<Out: 'static>
19{
20 fn spawn_handle_local_obj( &self, future: LocalFutureObj<'static, Out> ) -> Result<JoinHandle<Out>, SpawnError>;
23}
24
25
26pub trait LocalSpawnHandleExt<Out: 'static> : LocalSpawnHandle<Out>
29{
30 fn spawn_handle_local( &self, future: impl Future<Output = Out> + 'static ) -> Result<JoinHandle<Out>, SpawnError>;
34}
35
36
37impl<T, Out> LocalSpawnHandleExt<Out> for T
38
39 where T : LocalSpawnHandle<Out> + ?Sized ,
40 Out: 'static ,
41{
42 fn spawn_handle_local( &self, future: impl Future<Output = Out> + 'static ) -> Result<JoinHandle<Out>, SpawnError>
43 {
44 self.spawn_handle_local_obj( LocalFutureObj::new(future.boxed_local()) )
45 }
46}