runtime_bounds/
runtime_bounds.rs1use pi_async_runtime::prelude::*;
3use pi_async_runtime::{ExecutorHooks, IdlePolicy, ManualClock};
4use std::{
5 cell::Cell,
6 future::Future,
7 marker::PhantomPinned,
8 pin::Pin,
9 rc::Rc,
10 task::{Context, Poll},
11};
12
13struct Borrowed<'a> {
14 value: &'a Rc<usize>,
15 fixed: PhantomPinned,
16}
17impl Future for Borrowed<'_> {
18 type Output = Rc<usize>;
19 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
20 Poll::Ready(Rc::clone(self.as_ref().get_ref().value))
21 }
22}
23struct SendNotSync {
24 value: Cell<usize>,
25 fixed: PhantomPinned,
26}
27impl Future for SendNotSync {
28 type Output = usize;
29 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
30 Poll::Ready(self.as_ref().get_ref().value.get())
31 }
32}
33struct LocalPolicy(Rc<()>);
34impl IdlePolicy for LocalPolicy {}
35struct LocalHooks(Rc<()>);
36impl ExecutorHooks for LocalHooks {}
37fn send_sync<T: Send + Sync>() {}
38fn capabilities<T: pi_async_runtime::RuntimeCapabilities>() {}
39fn roots(runtime: &ConcurrentRuntime, handle: &Handle) {
40 let value = Rc::new(7);
41 let _: Rc<usize> = runtime.block_on(Borrowed {
42 value: &value,
43 fixed: PhantomPinned,
44 });
45 let _: Rc<usize> = handle.block_on(Borrowed {
46 value: &value,
47 fixed: PhantomPinned,
48 });
49 let _ = runtime.timeout_on(
50 Borrowed {
51 value: &value,
52 fixed: PhantomPinned,
53 },
54 std::time::Duration::from_millis(1),
55 );
56 let _ = handle.spawn(SendNotSync {
57 value: Cell::new(3),
58 fixed: PhantomPinned,
59 });
60 let _ = ConcurrentRuntime::spawn_local(async { Rc::new(1usize) });
61 let _ = ConcurrentRuntime::spawn_local_front(async { Rc::new(2usize) });
62 let _ = SerialRuntime::idle_local(async { Cell::new(4usize) });
63 let _ = handle.wait_one_timeout::<Rc<usize>>(std::time::Duration::from_secs(2));
64}
65fn declarations(clock: ManualClock) {
66 send_sync::<Handle>();
67 capabilities::<ConcurrentRuntime>();
68 capabilities::<SerialRuntime>();
69 capabilities::<Handle>();
70 let _ = ConcurrentRuntime::with_components(
71 clock,
72 LocalPolicy(Rc::new(())),
73 LocalHooks(Rc::new(())),
74 RuntimeOptions::default(),
75 );
76}
77fn main() {}