toml_query/
value.rs

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