• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Demo library to ensure that serde_json_lenient is working independently of
6 // its integration with Chromium.
7 
8 use serde_json_lenient::{Result, Value};
9 
10 #[cxx::bridge]
11 mod ffi {
12     extern "Rust" {
serde_works() -> bool13         fn serde_works() -> bool;
14     }
15 }
16 
serde_works() -> bool17 fn serde_works() -> bool {
18     parses_ok().unwrap_or_default()
19 }
20 
parses_ok() -> Result<bool>21 fn parses_ok() -> Result<bool> {
22     let data = r#"
23         {
24             "name": "Slartibartfast",
25             "planets": [ "Magrathea" ]
26         }"#;
27     let v: Value = serde_json_lenient::from_str(data)?;
28     Ok(v["name"] == "Slartibartfast" && v["planets"][0] == "Magrathea")
29 }
30