I have the following code:
let mut v2: Value;
let mut ts = v["response"]["ts"].as_str().unwrap();
...
loop {
v2 = longpoll_question(server.clone(),ts,key.clone());
if v2["ts"].as_str() == None {
continue;
}
ts = v2["ts"].as_str().unwrap();
...
}
Here I am getting a response from server which is in JSON format, and then retrieving a "ts" value from it that is needed for the next request to the server. Sometimes the value returned by server is "None" (presumably, network issues or remote API problems) and that was causing a crash, so I decided to check whether the value is None before unwrapping. This, however, refuses to compile with E0506
and I have no idea why. Could you please explain?