Should we allow Block<dyn FnMut()>, and how would we do it safely?
At the very least, we'd have to prevent any form of Block::copy/RcBlock::clone on these, as that could lead to multiple mutable references being present. In particular, it is difficult to prevent re-entrancy if the block is shared.
This decision is blocked on a resolution in https://github.com/madsmtm/objc2/issues/563, though we might still decide to allow FnMut in block2, even if we don't allow it in objc2, as most (non-@escaping, non-@Sendable) blocks (probably) really are safely mutable.
Upstream issue: https://github.com/SSheldon/rust-block/issues/12.
Should we allow
Block<dyn FnMut()>
, and how would we do it safely?At the very least, we'd have to prevent any form of
Block::copy
/RcBlock::clone
on these, as that could lead to multiple mutable references being present. In particular, it is difficult to prevent re-entrancy if the block is shared.This decision is blocked on a resolution in https://github.com/madsmtm/objc2/issues/563, though we might still decide to allow
FnMut
inblock2
, even if we don't allow it inobjc2
, as most (non-@escaping
, non-@Sendable
) blocks (probably) really are safely mutable.See also https://github.com/madsmtm/objc2/issues/168#issuecomment-1889026495 for discussion on why
FnOnce
is impossible, we should document that somewhere more visible when tackling this issue.