(f: F)
| 246 | #[cfg(feature = "std")] |
| 247 | #[inline] |
| 248 | pub fn try_defer_drop<F>(f: F) |
| 249 | where |
| 250 | F: FnOnce() + 'static, |
| 251 | { |
| 252 | let should_defer = IN_DEFERRED_CONTEXT.with(|in_ctx| in_ctx.get()); |
| 253 | |
| 254 | if should_defer { |
| 255 | DEFERRED_QUEUE.with(|q| { |
| 256 | q.borrow_mut().push(Box::new(f)); |
| 257 | }); |
| 258 | } else { |
| 259 | f(); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /// Flush all deferred drop operations. |
| 264 | /// This is automatically called when exiting a deferred context. |