Creating a DST struct with a dyn FnMut

⚓ Rust    📅 2025-12-31    👤 surdeus    👁️ 1      

surdeus

Hi, I'm looking to create instances of this struct:

struct DelayedConstraint<'s, 'acceptor> {
    next: Option<Box<Self>>,
    f: dyn FnMut() -> Result<(), &'acceptor dyn DelayedConstraintAcceptor<'s>> + 's,
}

I thought this'd be a nice exercise for DSTs. I needed a linked list for these anyway, and by including the closure object in the DelayedConstraint itself, I save a Box.

I'm seeing some crates that help with constructing DSTs, like dst-factory, or dyn_struct, but they seem to be awfully limited in what they support, and this support does not seem to include dyn function pointers.

What's right now the idiomatic way to construct/destruct such types? Likely there's no safe way, so I'm happy to reach for unsafe as well.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed