toml_query/
value.rs

1/// # Value extension
2///
3/// Extension trait for the toml::Value type
4///
5use toml::Value;
6
7use crate::delete::TomlValueDeleteExt;
8use crate::error::Result;
9use crate::insert::TomlValueInsertExt;
10use crate::read::TomlValueReadExt;
11use crate::set::TomlValueSetExt;
12
13/// Conveniance trait over
14///
15///  * TomlValueReadExt
16///  * TomlValueSetExt
17///
18/// for ease of use.
19///
20/// The very same goal can be achieved by importing each trait seperately.
21pub trait TomlValueExt<'doc>:
22    TomlValueReadExt<'doc> + TomlValueSetExt + TomlValueDeleteExt + TomlValueInsertExt
23{
24    //
25    // READ functionality
26    //
27
28    /// See documentation of `TomlValueReadExt`
29    #[inline]
30    fn read_with_seperator(&'doc self, query: &str, sep: char) -> Result<Option<&'doc Value>> {
31        TomlValueReadExt::read_with_seperator(self, query, sep)
32    }
33
34    /// See documentation of `TomlValueReadExt`
35    #[inline]
36    fn read_mut_with_seperator(
37        &'doc mut self,
38        query: &str,
39        sep: char,
40    ) -> Result<Option<&'doc mut Value>> {
41        TomlValueReadExt::read_mut_with_seperator(self, query, sep)
42    }
43
44    /// See documentation of `TomlValueReadExt`
45    #[inline]
46    fn read(&'doc self, query: &str) -> Result<Option<&'doc Value>> {
47        TomlValueReadExt::read_with_seperator(self, query, '.')
48    }
49
50    /// See documentation of `TomlValueReadExt`
51    #[inline]
52    fn read_mut(&'doc mut self, query: &str) -> Result<Option<&'doc mut Value>> {
53        TomlValueReadExt::read_mut_with_seperator(self, query, '.')
54    }
55
56    //
57    // SET functionality
58    //
59
60    /// See documentation of `TomlValueSetExt`
61    #[inline]
62    fn set_with_seperator(
63        &mut self,
64        query: &str,
65        sep: char,
66        value: Value,
67    ) -> Result<Option<Value>> {
68        TomlValueSetExt::set_with_seperator(self, query, sep, value)
69    }
70
71    /// See documentation of `TomlValueSetExt`
72    #[inline]
73    fn set(&mut self, query: &str, value: Value) -> Result<Option<Value>> {
74        TomlValueSetExt::set_with_seperator(self, query, '.', value)
75    }
76
77    //
78    // DELETE functionality
79    //
80
81    /// See documentation of `TomlValueDeleteExt`
82    #[inline]
83    fn delete_with_seperator(&mut self, query: &str, sep: char) -> Result<Option<Value>> {
84        TomlValueDeleteExt::delete_with_seperator(self, query, sep)
85    }
86
87    /// See documentation of `TomlValueDeleteExt`
88    #[inline]
89    fn delete(&mut self, query: &str) -> Result<Option<Value>> {
90        TomlValueDeleteExt::delete(self, query)
91    }
92
93    //
94    // INSERT functionality
95    //
96
97    /// See documentation of `TomlValueInsertExt`
98    #[inline]
99    fn insert_with_seperator(
100        &mut self,
101        query: &str,
102        sep: char,
103        value: Value,
104    ) -> Result<Option<Value>> {
105        TomlValueInsertExt::insert_with_seperator(self, query, sep, value)
106    }
107
108    /// See documentation of `TomlValueInsertExt`
109    #[inline]
110    fn insert(&mut self, query: &str, value: Value) -> Result<Option<Value>> {
111        TomlValueInsertExt::insert(self, query, value)
112    }
113}
114
115impl<'doc> TomlValueExt<'doc> for Value {}