Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Deserialize An Integer

This is a test to bug hunt a problem I'm having in Neopoligen. It's working here as expected. Still TBD on what's up with the other thing.

Code

//! ```cargo
//! [dependencies]
//! serde = { version = "1.0.195", features = ["derive"] }
//! serde_json = "1.0.111"
//! ```

#![allow(dead_code)]
use serde::Deserialize;
use serde_json;

#[derive(Debug, Deserialize)]
pub struct Widget {
  value: i32
}

fn main() {
  let json_string = r#"{ "value": -5 }"#;
  let data: Widget = serde_json::from_str(json_string).unwrap();
  println!("{:?}", data);
}

Results

Widget { value: -5 }