Debian Codegraph @

src/rt/mod.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#, Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#};
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#;
6
7 #[cfg(feature = "_rt-async-std")]
8 pub mod rt_async_stdrust-analyzer cargo sqlx-core 0.8.3 rt/rt_async_std/;
9
10 #[cfg(feature = "_rt-tokio")]
11 pub mod rt_tokiorust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/;
12
13 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.20 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.20 Error:)]
14 #[error("operation timed out")]
15 pub struct TimeoutErrorrust-analyzer cargo sqlx-core 0.8.3 rt/TimeoutError#(());
16
17 pub enum JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#<T> {
18 #[cfg(feature = "_rt-async-std")]
19 AsyncStdrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#AsyncStd#(async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::JoinHandlerust-analyzer cargo async-std 1.13.2 task/join_handle/JoinHandle#<T>),
20 #[cfg(feature = "_rt-tokio")]
21 Tokiorust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#Tokio#(tokiorust-analyzer cargo tokio 1.53.1 crate/::taskrust-analyzer cargo tokio 1.53.1 task/::JoinHandlerust-analyzer cargo tokio 1.53.1 runtime/task/join/JoinHandle#<T>),
22 // `PhantomData<T>` requires `T: Unpin`
23 _Phantomrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#_Phantom#(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<fn() -> T>),
24 }
25
26 pub async fn timeoutrust-analyzer cargo sqlx-core 0.8.3 rt/timeout().<F: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#>(duration: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, f: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<F::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#, TimeoutErrorrust-analyzer cargo sqlx-core 0.8.3 rt/TimeoutError#> {
27 #[cfg(feature = "_rt-tokio")]
28 if rt_tokiorust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/::availablerust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/available().() {
29 return tokiorust-analyzer cargo tokio 1.53.1 crate/::timerust-analyzer cargo tokio 1.53.1 time/::timeoutrust-analyzer cargo tokio 1.53.1 time/timeout/timeout().(duration, f)
30 .rust-analyzer cargo tokio 1.53.1 time/timeout/impl#[`Timeout<T>`][Future]poll().awaitrust-analyzer cargo tokio 1.53.1 time/timeout/impl#[`Timeout<T>`][Future]poll().
31 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| TimeoutErrorrust-analyzer cargo sqlx-core 0.8.3 rt/TimeoutError#(()));
32 }
33
34 #[cfg(feature = "_rt-async-std")]
35 {
36 async_stdrust-analyzer cargo async-std 1.13.2 crate/::futurerust-analyzer cargo async-std 1.13.2 future/::timeoutrust-analyzer cargo async-std 1.13.2 future/timeout/timeout().(duration, f)
37 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
38 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| TimeoutErrorrust-analyzer cargo sqlx-core 0.8.3 rt/TimeoutError#(()))
39 }
40
41 #[cfg(not(feature = "_rt-async-std"))]
42 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().((duration, f))
43 }
44
45 pub async fn sleeprust-analyzer cargo sqlx-core 0.8.3 rt/sleep().(duration: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) {
46 #[cfg(feature = "_rt-tokio")]
47 if rt_tokiorust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/::availablerust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/available().() {
48 return tokiorust-analyzer cargo tokio 1.53.1 crate/::timerust-analyzer cargo tokio 1.53.1 time/::sleeprust-analyzer cargo tokio 1.53.1 time/sleep/sleep().(duration).rust-analyzer cargo tokio 1.53.1 time/sleep/impl#[Sleep][Future]poll().awaitrust-analyzer cargo tokio 1.53.1 time/sleep/impl#[Sleep][Future]poll().;
49 }
50
51 #[cfg(feature = "_rt-async-std")]
52 {
53 async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::sleeprust-analyzer cargo async-std 1.13.2 task/sleep/sleep().(duration).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
54 }
55
56 #[cfg(not(feature = "_rt-async-std"))]
57 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().(duration)
58 }
59
60 #[track_caller]
61 pub fn spawnrust-analyzer cargo sqlx-core 0.8.3 rt/spawn().<F>(fut: F) -> JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#<F::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#>
62 where
63 F: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static,
64 F::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static,
65 {
66 #[cfg(feature = "_rt-tokio")]
67 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(handle) = tokiorust-analyzer cargo tokio 1.53.1 crate/::runtimerust-analyzer cargo tokio 1.53.1 runtime/::Handlerust-analyzer cargo tokio 1.53.1 runtime/handle/Handle#::try_currentrust-analyzer cargo tokio 1.53.1 runtime/handle/impl#[Handle]try_current().() {
68 return JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#::Tokiorust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#Tokio#(handle.spawnrust-analyzer cargo tokio 1.53.1 runtime/handle/impl#[Handle]spawn().(fut));
69 }
70
71 #[cfg(feature = "_rt-async-std")]
72 {
73 JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#::AsyncStdrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#AsyncStd#(async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::spawnrust-analyzer cargo async-std 1.13.2 task/spawn/spawn().(fut))
74 }
75
76 #[cfg(not(feature = "_rt-async-std"))]
77 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().(fut)
78 }
79
80 #[track_caller]
81 pub fn spawn_blockingrust-analyzer cargo sqlx-core 0.8.3 rt/spawn_blocking().<F, R>(f: F) -> JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#<R>
82 where
83 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> R + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static,
84 R: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static,
85 {
86 #[cfg(feature = "_rt-tokio")]
87 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(handle) = tokiorust-analyzer cargo tokio 1.53.1 crate/::runtimerust-analyzer cargo tokio 1.53.1 runtime/::Handlerust-analyzer cargo tokio 1.53.1 runtime/handle/Handle#::try_currentrust-analyzer cargo tokio 1.53.1 runtime/handle/impl#[Handle]try_current().() {
88 return JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#::Tokiorust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#Tokio#(handle.spawn_blockingrust-analyzer cargo tokio 1.53.1 runtime/handle/impl#[Handle]spawn_blocking().(f));
89 }
90
91 #[cfg(feature = "_rt-async-std")]
92 {
93 JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#::AsyncStdrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#AsyncStd#(async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::spawn_blockingrust-analyzer cargo async-std 1.13.2 task/spawn_blocking/spawn_blocking().(f))
94 }
95
96 #[cfg(not(feature = "_rt-async-std"))]
97 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().(f)
98 }
99
100 pub async fn yield_nowrust-analyzer cargo sqlx-core 0.8.3 rt/yield_now().() {
101 #[cfg(feature = "_rt-tokio")]
102 if rt_tokiorust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/::availablerust-analyzer cargo sqlx-core 0.8.3 rt/rt_tokio/available().() {
103 return tokiorust-analyzer cargo tokio 1.53.1 crate/::taskrust-analyzer cargo tokio 1.53.1 task/::yield_nowrust-analyzer cargo tokio 1.53.1 task/yield_now/yield_now().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
104 }
105
106 #[cfg(feature = "_rt-async-std")]
107 {
108 async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::yield_nowrust-analyzer cargo async-std 1.13.2 task/yield_now/yield_now().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
109 }
110
111 #[cfg(not(feature = "_rt-async-std"))]
112 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().(())
113 }
114
115 #[track_caller]
116 pub fn test_block_onrust-analyzer cargo sqlx-core 0.8.3 rt/test_block_on().<F: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#>(f: F) -> F::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# {
117 #[cfg(feature = "_rt-tokio")]
118 {
119 return tokiorust-analyzer cargo tokio 1.53.1 crate/::runtimerust-analyzer cargo tokio 1.53.1 runtime/::Builderrust-analyzer cargo tokio 1.53.1 runtime/builder/Builder#::new_current_threadrust-analyzer cargo tokio 1.53.1 runtime/builder/impl#[Builder]new_current_thread().()
120 .enable_allrust-analyzer cargo tokio 1.53.1 runtime/builder/impl#[Builder]enable_all().()
121 .buildrust-analyzer cargo tokio 1.53.1 runtime/builder/impl#[Builder]build().()
122 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to start Tokio runtime")
123 .block_onrust-analyzer cargo tokio 1.53.1 runtime/runtime/impl#[Runtime]block_on().(f);
124 }
125
126 #[cfg(all(feature = "_rt-async-std", not(feature = "_rt-tokio")))]
127 {
128 async_stdrust-analyzer cargo async-std 1.13.2 crate/::taskrust-analyzer cargo async-std 1.13.2 task/::block_onrust-analyzer cargo async-std 1.13.2 task/block_on/block_on().(f)
129 }
130
131 #[cfg(not(any(feature = "_rt-async-std", feature = "_rt-tokio")))]
132 {
133 missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().(f)
134 }
135 }
136
137 #[track_caller]
138 pub fn missing_rtrust-analyzer cargo sqlx-core 0.8.3 rt/missing_rt().<T>(_unused: T) -> ! {
139 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(feature = "_rt-tokio") {
140 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("this functionality requires a Tokio context")
141 }
142
143 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("either the `runtime-async-std` or `runtime-tokio` feature must be enabled")
144 }
145
146 impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for JoinHandlerust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#<T> {
147 type Outputrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]Output# = T;
148
149 #[track_caller]
150 fn pollrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]poll().(mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]>, cx: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<Selfrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#> {
151 match &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][DerefMut]deref_mut().self {
152 #[cfg(feature = "_rt-async-std")]
153 Selfrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]::AsyncStdrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#AsyncStd#(handle) => Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(handle).pollrust-analyzer cargo async-std 1.13.2 task/join_handle/impl#[`JoinHandle<T>`][Future]poll().(cx),
154 #[cfg(feature = "_rt-tokio")]
155 Selfrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]::Tokiorust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#Tokio#(handle) => Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(handle)
156 .pollrust-analyzer cargo tokio 1.53.1 runtime/task/join/impl#[`JoinHandle<T>`][Future]poll().(cx)
157 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/impl#[`Poll<T>`]map().(|res| res.expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("spawned task panicked")),
158 Selfrust-analyzer cargo sqlx-core 0.8.3 rt/impl#[`JoinHandle<T>`][Future]::_Phantomrust-analyzer cargo sqlx-core 0.8.3 rt/JoinHandle#_Phantom#(_) => {
159 let _ = cx;
160 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("runtime should have been checked on spawn")
161 }
162 }
163 }
164 }