Calling FnOnce inside a custom DST
⚓ Rust 📅 2025-09-13 👤 surdeus 👁️ 11Is there any way to call a FnOnce inside a custom DST in a box? Unsafe or unstable is okay.
struct TaskNode<T: FnOnce() + ?Sized> {
next: Option<Box<TaskNode<dyn FnOnce()>>>,
task: T,
}
fn run_tasks(mut head: Option<Box<TaskNode<dyn FnOnce()>>>) {
while let Some(node) = head {
head = node.next;
// How to actually do this??
(node.task)();
}
}
8 posts - 3 participants
🏷️ Rust_feed