use anyhow::{anyhow,bail};
use std::path::PathBuf;
use crate::common;
crate::common::impl_macro!(Toml, "toml");
pub unsafe trait Toml: serde::Serialize + serde::de::DeserializeOwned {
#[doc(hidden)]
#[inline(always)]
fn __from_file() -> Result <Self, anyhow::Error> {
Self::from_bytes(&Self::read_to_bytes()?)
}
#[doc(hidden)]
#[inline(always)]
fn __from_path(path: &std::path::Path) -> Result<Self, anyhow::Error> {
Self::from_bytes(&crate::common::path_to_bytes(path)?)
}
#[inline(always)]
fn to_bytes(&self) -> Result<Vec<u8>, anyhow::Error> {
Ok(Self::to_string(self)?.into_bytes())
}
#[inline(always)]
fn from_bytes(bytes: &[u8]) -> Result<Self, anyhow::Error> {
common::convert_error(toml_edit::de::from_slice(bytes))
}
#[inline(always)]
fn to_string(&self) -> Result<String, anyhow::Error> {
common::convert_error(toml_edit::ser::to_string_pretty(self))
}
#[inline(always)]
fn from_string(string: &str) -> Result<Self, anyhow::Error> {
common::convert_error(toml_edit::de::from_str(string))
}
common::impl_string!("toml");
}