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

Any way to use a FnMut with add_method? #315

Closed
Kampfkarren opened this issue Sep 17, 2018 · 1 comment
Closed

Any way to use a FnMut with add_method? #315

Kampfkarren opened this issue Sep 17, 2018 · 1 comment

Comments

@Kampfkarren
Copy link

I want to use the following code:

	io.add_method("initialize", |_| {
		check_initialized!(state);
		state.initialized = true;
		Ok(rpc::Value::String("DONE".to_string()))
	});

This gives me the error:

32 |     io.add_method("initialize", |_| {
   |        ----------               ^^^ this closure implements `FnMut`, not `Fn`
   |        |
   |        the requirement to implement `Fn` derives from here
33 |         check_initialized!(state);
34 |         state.initialized = true;
   |         ----- closure is `FnMut` because it mutates the variable `state` here

I'm not sure how to resolve this. I'm new to Rust.

@tomusdrw
Copy link
Contributor

@Kampfkarren the methods can be called by multiple threads, os they have to be Sync. Please wrap any mutability into RwLock, Mutex or use Atomic* structs.

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

No branches or pull requests

2 participants