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
|
import tom
import gleam/result
pub type TomError {
TomParseError(error: tom.ParseError)
TomGetError(error: tom.GetError)
}
pub fn get_string(
toml_content: String,
key_path: List(String),
) -> Result(String, TomError) {
use toml <- result.try(
tom.parse(toml_content <> "\n")
|> result.map_error(TomParseError),
)
use value <- result.try(
tom.get_string(toml, key_path)
|> result.map_error(TomGetError),
)
Ok(value)
}
pub fn get_bool(
toml_content: String,
key_path: List(String),
) -> Result(Bool, TomError) {
use toml <- result.try(
tom.parse(toml_content <> "\n")
|> result.map_error(TomParseError),
)
use value <- result.try(
tom.get_bool(toml, key_path)
|> result.map_error(TomGetError),
)
Ok(value)
}
pub fn get_int(
toml_content: String,
key_path: List(String),
) -> Result(Int, TomError) {
use toml <- result.try(
tom.parse(toml_content <> "\n")
|> result.map_error(TomParseError),
)
use value <- result.try(
tom.get_int(toml, key_path)
|> result.map_error(TomGetError),
)
Ok(value)
}
|