forked from Dicklesworthstone/asupersync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros_basic.rs
More file actions
72 lines (59 loc) · 1.48 KB
/
Copy pathmacros_basic.rs
File metadata and controls
72 lines (59 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#![allow(missing_docs)]
#![allow(
clippy::trivially_copy_pass_by_ref,
clippy::unnecessary_wraps,
clippy::unused_self
)]
#[cfg(feature = "proc-macros")]
mod demo {
use asupersync::{join, scope, spawn};
use std::future::Future;
use std::marker::PhantomData;
#[derive(Clone, Copy)]
struct MiniCx;
struct MiniScope;
struct MiniState;
#[derive(Debug)]
struct MiniError;
struct MiniHandle<T>(PhantomData<T>);
impl MiniCx {
fn scope(&self) -> MiniScope {
MiniScope
}
#[allow(dead_code)]
fn scope_with_budget(&self, _budget: asupersync::Budget) -> MiniScope {
MiniScope
}
}
impl MiniScope {
fn spawn_registered<F, Fut>(
&self,
_state: &mut MiniState,
_cx: &MiniCx,
f: F,
) -> Result<MiniHandle<Fut::Output>, MiniError>
where
F: FnOnce(MiniCx) -> Fut,
Fut: Future,
{
std::mem::drop(f(MiniCx));
Ok(MiniHandle(PhantomData))
}
}
pub async fn demo() {
let cx = MiniCx;
let mut state = MiniState;
let __state = &mut state;
let (a, b) = join!(async { 1 }, async { 2 });
let _ = scope!(cx, {
let _handle = spawn!(async { 42 });
(a, b)
});
}
}
#[cfg(feature = "proc-macros")]
fn main() {
std::mem::drop(demo::demo());
}
#[cfg(not(feature = "proc-macros"))]
fn main() {}