While working with serde_json for reading json documents, I wrote the following line of code to obtain the result of unwrapping the return value of serde_json::from_str
:
fn get_json_content(content_s: &str) -> Option<Value> {
let ms: String = serde_json::from_str(content_s).unwrap; // <--
match serde_json::from_str(content_s) {
Ok(some_value) => Some(some_value),
Err(_) => None
}
}
As you can see, I forgot the ()
on the end of the call to unwrap
, which resulted in the following error:
error: attempted to take value of method
unwrap
on typecore::result::Result<_, serde_json::error::Error>
let ms: String = serde_json::from_str(content_s).unwrap;
But when I looked at this a bit further, the thing that struck me as odd was:
core::result::Result<_, serde_json::error::Error>
I understand what underscore means in a match context, but to instantiate a generic? So what does this mean? I couldn't find any answers in the Rust book, or reference, or a web search.