rust-block icon indicating copy to clipboard operation
rust-block copied to clipboard

Block should be able to take FnMut, as opposed to just Fn

Open adamnemecek opened this issue 4 years ago • 2 comments

adamnemecek avatar Feb 15 '21 01:02 adamnemecek

This would be useful for me too. My use case is wanting to move from an xpc_object_t into a Rust HashMap:

let mut hm: HashMap<String, XPCObject> = HashMap::new();

let block = ConcreteBlock::new(|key: *const c_char, value: xpc_object_t| {
    let str_key = unsafe { CStr::from_ptr(key).to_string_lossy().to_string() };
    hm.insert(str_key, XPCObject { data: value });
});

EDIT: Was able to use Rc<RefCell<HashMap>> instead

mach-kernel avatar Feb 26 '21 19:02 mach-kernel

@mach-kernel I wonder if it's a good idea to have two versions, a Fn and a FnMut version. I think that just a FnMut version should suffice. If you are already dealing with these APIs, your immutability is fucked anyway.

adamnemecek avatar Feb 26 '21 19:02 adamnemecek