Hi Folks,
maybe I should have posted on SO, but I had the impression that here the conversations are deeper and more interesting, if it is not appropriate, please just tell me and I will move.
Anyway, I have this piece of code that I do not understand very well what is happening.
Given a Result<T, U>, I need to check that the result is actually an Ok(T) if it is I need to call a function on T, and based on the result of such function call another procedure.
Finally, no matter what, I need to call a third function on the initial Result.
Only the last function should take the property of the Result, all the intermediate procedure should just be able to read.
To make thing simpler, in code it looks like this:
fn return_value(client: BlockedClient, result: Result<QueryResult, err::RediSQLError>) {
match result {
Err(_) => {} // do nothing
Ok(query_result) => match query_result.to_replicate() { //line 344
false => {} // do nothing
true => {
// do something without touching `result`
let ctx = ffi::RedisModule_GetThreadSafeContext.unwrap()(client.client);
ffi::RedisModule_ReplicateVerbatim.unwrap()(ctx);
}
},
}
// we don't care of what happened before, now use result
ffi::RedisModule_UnblockClient.unwrap()(
client.client,
Box::into_raw(Box::new(result)) as *mut std::os::raw::c_void, //line 362
);
}
impl QueryResult {
pub fn to_replicate(self) -> bool {
// may return true or may return false
}
}
Unfortunately this code does not compile:
error[E0382]: use of partially moved value: `result`
--> src/redis.rs:362:79
|
344 | Ok(query_result) => {
| ------------ value moved here
...
362 | Box::into_raw(Box::new(result)) as *mut std::os::raw::c_void);
| ^^^^^^ value used here after move
|
= note: move occurs because `(result:std::prelude::v1::Ok).0` has type `redis::QueryResult`, which does not implement the `Copy` trait
error: aborting due to previous error
I do not understand why the Ok() (/or the match) moves the value inside.
Can somebody enlight me?