use anyhow::{anyhow,bail};
use std::path::PathBuf;
use crate::common;
use std::io::{
Read,Write,
BufReader,
};
crate::common::impl_macro!(Ron, "ron");
pub unsafe trait Ron: serde::Serialize + serde::de::DeserializeOwned {
#[doc(hidden)]
#[inline(always)]
fn __from_file() -> Result <Self, anyhow::Error> {
let path = Self::absolute_path()?;
let file = std::fs::File::open(path)?;
Ok(ron::de::from_reader(BufReader::new(file))?)
}
#[doc(hidden)]
#[inline(always)]
fn __from_path(path: &std::path::Path) -> Result<Self, anyhow::Error> {
let file = std::fs::File::open(path)?;
Ok(ron::de::from_reader(BufReader::new(file))?)
}
#[inline(always)]
fn to_bytes(&self) -> Result<Vec<u8>, anyhow::Error> {
let mut vec = vec![];
ron::ser::to_writer_pretty(&mut vec, self, ron::ser::PrettyConfig::new())?;
Ok(vec)
}
#[inline(always)]
fn from_bytes(bytes: &[u8]) -> Result<Self, anyhow::Error> {
common::convert_error(ron::de::from_bytes(bytes))
}
#[inline(always)]
fn to_string(&self) -> Result<String, anyhow::Error> {
common::convert_error(ron::ser::to_string_pretty(self, ron::ser::PrettyConfig::new()))
}
#[inline(always)]
fn from_string(string: &str) -> Result<Self, anyhow::Error> {
common::convert_error(ron::de::from_str(string))
}
common::impl_string!("ron");
}