Skip to content

Allow FnMut in blocks? #571

@madsmtm

Description

@madsmtm

Upstream issue: SSheldon/rust-block#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 #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, see #572) blocks (probably) really are safely mutable.

See also #168 (comment) for discussion on why FnOnce is impossible, we should document that somewhere more visible when tackling this issue. Or maybe add RcBlock::once, similar to wasm-bindgen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-block2Affects the `block2` crateenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions