A type hint, or type annotation, explicitly associates a type with a value, variable, parameter, or return result. Rust requires function inputs and outputs to be annotated, while usually inferring local variable types statically. section 1.4.3
Use annotations when inference needs direction or when an interface benefits from explicit types:
- Annotate a generic result when the compiler cannot infer the expected type. section 6.3
- Leave ordinary local types inferred when surrounding operations make them unambiguous. section 1.4.3
- Use explicit input and output types to make function contracts clear and prevent incompatible values. section 1.4.3
Guiding JSON deserialization
A JSON parser has a generic return type, so Rust needs a target type: `let parsed: Data = serde_json::from_str(input).unwrap();`. The annotation identifies the desired struct; deriving `Deserialize` then enables parsing, while deriving `Debug` enables formatted output. section 6.3
let parsed: Data = serde_json::from_str(input).unwrap();
Shows the smallest annotation that resolves the compiler's ambiguous JSON result. section 6.3
















