rust-block
rust-block copied to clipboard
Block should be able to take FnMut, as opposed to just Fn
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 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.