Skip to content

Mutable method receivers in closures #18755

Discussion options

You must be logged in to vote

I have not found an answer this this question. I have rewritten the function from this form:

fn (mut c BaseClient) attempt_process(mut cmd Cmder) ! {
	c.with_connection(fn [mut cmd] (mut cn pool.Connection) ! {
		cn.with_writer(fn [cmd] (mut wr proto.Writer) ! {
			write_cmd(mut wr, cmd)!
		})!
		cn.with_reader(cmd.read_reply)!
	})!
}

To this form:

fn (mut c BaseClient) attempt_process(mut cmd Cmder) ! {
	c.with_connection(fn [mut cmd] (mut cn pool.Connection) ! {
		cn.with_writer(fn [cmd] (mut wr proto.Writer) ! {
			write_cmd(mut wr, cmd)!
		})!
		cn.with_reader(fn [mut cmd] (mut rd proto.Reader) ! {
			cmd.read_reply(mut rd)!
		})!
	})!
}

When the function is written this way, cmd (whi…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@JalonSolov
Comment options

@einar-hjortdal
Comment options

@JalonSolov
Comment options

@Wajinn
Comment options

@einar-hjortdal
Comment options

Comment options

You must be logged in to vote
1 reply
@einar-hjortdal
Comment options

Answer selected by einar-hjortdal
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants