Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamnemecek
Copy link

No description provided.

@mach-kernel
Copy link

mach-kernel commented Feb 26, 2021

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

@adamnemecek
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants