use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::path::Path;
use anyhow::Context;
use serde::de::DeserializeOwned;
use serde::Serialize;
pub mod files;
pub mod java;
pub mod minecraft;
pub mod persistent;
pub mod update;
pub fn json_from_file<D: DeserializeOwned>(path: impl AsRef<Path>) -> anyhow::Result<D> {
let file = BufReader::new(File::open(path).context("Failed to open file")?);
Ok(simd_json::from_reader(file)?)
}
pub fn json_to_file<S: Serialize>(path: impl AsRef<Path>, data: &S) -> anyhow::Result<()> {
let file = BufWriter::new(File::create(path).context("Failed to open file")?);
simd_json::to_writer(file, data).context("Failed to serialize data to file")?;
Ok(())
}
pub fn json_to_file_pretty<S: Serialize>(path: impl AsRef<Path>, data: &S) -> anyhow::Result<()> {
let file = BufWriter::new(File::create(path).context("Failed to open file")?);
serde_json::to_writer_pretty(file, data).context("Failed to serialize data to file")?;
Ok(())
}
pub fn json_to_file_pretty_fast<S: Serialize>(
path: impl AsRef<Path>,
data: &S,
) -> anyhow::Result<()> {
let file = BufWriter::new(File::create(path).context("Failed to open file")?);
simd_json::to_writer_pretty(file, data).context("Failed to serialize data to file")?;
Ok(())
}