vector/config/loading/
source.rs1use std::io::Read;
2
3use serde_toml_merge::merge_into_table;
4use toml::{map::Map, value::Table};
5
6use super::{ComponentHint, Loader, Process};
7
8pub struct SourceLoader {
9 table: Table,
10}
11
12impl SourceLoader {
13 pub fn new() -> Self {
14 Self { table: Map::new() }
15 }
16}
17
18impl Default for SourceLoader {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24impl Process for SourceLoader {
25 fn prepare<R: Read>(&mut self, mut input: R) -> Result<String, Vec<String>> {
28 let mut source_string = String::new();
29 input
30 .read_to_string(&mut source_string)
31 .map_err(|e| vec![e.to_string()])?;
32
33 Ok(source_string)
34 }
35
36 fn merge(&mut self, table: Table, _hint: Option<ComponentHint>) -> Result<(), Vec<String>> {
38 merge_into_table(&mut self.table, table).map_err(|e| vec![e.to_string()])
39 }
40}
41
42impl Loader<Table> for SourceLoader {
43 fn take(self) -> Table {
45 self.table
46 }
47}