spacegate_config/service/config_format/
toml.rs1use std::ffi::{OsStr, OsString};
2
3use crate::BoxError;
4
5use super::ConfigFormat;
6#[derive(Debug, Clone)]
7pub struct Toml {
8 pub extension: OsString,
9}
10
11impl Default for Toml {
12 fn default() -> Self {
13 Self {
14 extension: OsString::from("toml"),
15 }
16 }
17}
18
19impl ConfigFormat for Toml {
20 fn extension(&self) -> &OsStr {
21 &self.extension
22 }
23 fn de<T: serde::de::DeserializeOwned>(&self, slice: &[u8]) -> Result<T, BoxError> {
24 Ok(toml::from_str(&String::from_utf8_lossy(slice))?)
25 }
26 fn ser<T: serde::Serialize>(&self, t: &T) -> Result<Vec<u8>, BoxError> {
27 Ok(toml::to_string_pretty(t)?.into())
28 }
29}