air_interpreter_value/lib.rs
1/*
2 * Copyright 2024 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * This file is based on serde_json crate by Erick Tryzelaar and David Tolnay
19 * licensed under conditions of MIT License and Apache License, Version 2.0.
20 */
21
22#[cfg(not(feature = "preserve_order"))]
23use std::collections::BTreeMap;
24use std::rc::Rc;
25
26// We only use our own error type; no need for From conversions provided by the
27// standard library's try! macro. This reduces lines of LLVM IR by 4%.
28macro_rules! tri {
29 ($e:expr $(,)?) => {
30 match $e {
31 core::result::Result::Ok(val) => val,
32 core::result::Result::Err(err) => return core::result::Result::Err(err),
33 }
34 };
35}
36
37mod value;
38
39pub use value::JValue;
40
41#[cfg(not(feature = "preserve_order"))]
42pub type Map<K, V> = BTreeMap<K, V>;
43
44#[cfg(feature = "preserve_order")]
45pub type Map<K, V> = indexmap::IndexMap<K, V>;
46
47// it is memory- and CPU-wise more effective than a string
48pub type JsonString = Rc<str>;