1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::{
    borrow::{Borrow, BorrowMut},
    fmt,
};

use serde::*;

use crate::value::Value;

/// The element type for box arrays
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Boxed(pub Value);

impl Boxed {
    /// Get the inner value
    pub fn as_value(&self) -> &Value {
        &self.0
    }
    /// Get the inner value mutably
    pub fn as_value_mut(&mut self) -> &mut Value {
        &mut self.0
    }
    /// Unwrap the inner value
    pub fn into_inner(self) -> Value {
        self.0
    }
}

impl fmt::Debug for Boxed {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl fmt::Display for Boxed {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl From<Value> for Boxed {
    fn from(v: Value) -> Self {
        Self(v)
    }
}

impl AsRef<Value> for Boxed {
    fn as_ref(&self) -> &Value {
        &self.0
    }
}

impl AsMut<Value> for Boxed {
    fn as_mut(&mut self) -> &mut Value {
        &mut self.0
    }
}

impl Borrow<Value> for Boxed {
    fn borrow(&self) -> &Value {
        &self.0
    }
}

impl BorrowMut<Value> for Boxed {
    fn borrow_mut(&mut self) -> &mut Value {
        &mut self.0
    }
}