error-concept

JSON error categories

Distinguish malformed syntax, a valid JSON shape with incompatible data, incomplete input and I/O failures. Handle them based on the application context rather than matching exact diagnostic strings. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): true true true Common mistake: Retrying permanent data errors as though they were temporary I/O failures.

Formal Syntax & Structure

rust syntaxrust
error.is_syntax(); error.is_data(); error.is_eof(); error.is_io()

Working Example

Example Snippetrust
fn main() {    let syntax = serde_json::from_str::<u32>("?").unwrap_err();    let data = serde_json::from_str::<u32>("true").unwrap_err();    let eof = serde_json::from_str::<Vec<u32>>("[").unwrap_err();    println!("{} {} {}", syntax.is_syntax(), data.is_data(), eof.is_eof());}
Rust Reference