From 89851b681da7db880ed3cf527ee3b3bb0be414c7 Mon Sep 17 00:00:00 2001 From: Speak2Erase Date: Fri, 31 May 2024 17:13:02 -0700 Subject: [PATCH] Use the crates.io version of alox --- Cargo.lock | 10 ++++---- Cargo.toml | 2 +- crates/core/src/data_cache.rs | 43 +++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3633d2c3..6a96227f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,8 +175,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alox-48" -version = "0.5.0-pre.2" -source = "git+https://github.com/Speak2Erase/alox-48#d12e1359ae0287773ac1612c71b26940f5ad3b3c" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10b95702b328de6416c5504d9d7d74438362f06ec907579d3be0f28ee94084dc" dependencies = [ "alox-48-derive", "enum-as-inner", @@ -187,8 +188,9 @@ dependencies = [ [[package]] name = "alox-48-derive" -version = "0.2.0" -source = "git+https://github.com/Speak2Erase/alox-48#d12e1359ae0287773ac1612c71b26940f5ad3b3c" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6152ba1b6253ae07208325b9902222d3b0fbf84d2500d95d14ad79e9e5745033" dependencies = [ "darling", "itertools 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index 30a78f0f..e232863f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ glam = { version = "0.24.2", features = ["bytemuck"] } image = "0.24.7" serde = { version = "1.0", features = ["derive"] } -alox-48 = { version = "0.5.0-pre.2", git = "https://github.com/Speak2Erase/alox-48" } +alox-48 = { version = "0.5.0" } ron = "0.8.1" rust-ini = "0.20.0" diff --git a/crates/core/src/data_cache.rs b/crates/core/src/data_cache.rs index 17f45b60..b5c95210 100644 --- a/crates/core/src/data_cache.rs +++ b/crates/core/src/data_cache.rs @@ -67,17 +67,10 @@ where let path = camino::Utf8PathBuf::from("Data").join(filename); let data = filesystem.read(path)?; - let mut trace = alox_48::path_to_error::Trace::new(); let mut de = alox_48::Deserializer::new(&data)?; - let de = alox_48::path_to_error::Deserializer::new(&mut de, &mut trace); + let result = alox_48::path_to_error::deserialize(&mut de); - T::deserialize(de).map_err(|e| { - let mut message = format!("Error {e}:\n"); - for context in trace.context.iter().rev() { - writeln!(message, " {}", context).unwrap(); - } - color_eyre::Report::msg(message) - }) + result.map_err(|(error, trace)| format_traced_error(error, trace)) } fn write_data( @@ -87,9 +80,12 @@ fn write_data( ) -> color_eyre::Result<()> { let path = camino::Utf8PathBuf::from("Data").join(filename); - let bytes = alox_48::to_bytes(data)?; + let mut serializer = alox_48::Serializer::new(); + alox_48::path_to_error::serialize(data, &mut serializer) + .map_err(|(error, trace)| format_traced_error(error, trace))?; + filesystem - .write(path, bytes) + .write(path, serializer.output) .map_err(color_eyre::Report::from) } @@ -107,13 +103,8 @@ where let mut de = alox_48::Deserializer::new(&data)?; let de = alox_48::path_to_error::Deserializer::new(&mut de, &mut trace); - luminol_data::helpers::nil_padded_alox::deserialize_with(de).map_err(|e| { - let mut message = format!("Error {e}:\n"); - for context in trace.context.iter().rev() { - writeln!(message, " {}", context).unwrap(); - } - color_eyre::Report::msg(message) - }) + luminol_data::helpers::nil_padded_alox::deserialize_with(de) + .map_err(|error| format_traced_error(error, trace)) } fn write_nil_padded( @@ -123,14 +114,28 @@ fn write_nil_padded( ) -> color_eyre::Result<()> { let path = camino::Utf8PathBuf::from("Data").join(filename); + let mut trace = alox_48::path_to_error::Trace::new(); let mut ser = alox_48::Serializer::new(); + let trace_ser = alox_48::path_to_error::Serializer::new(&mut ser, &mut trace); - luminol_data::helpers::nil_padded_alox::serialize_with(data, &mut ser)?; + luminol_data::helpers::nil_padded_alox::serialize_with(data, trace_ser) + .map_err(|error| format_traced_error(error, trace))?; filesystem .write(path, ser.output) .map_err(color_eyre::Report::from) } +fn format_traced_error( + error: impl std::fmt::Display, + trace: alox_48::path_to_error::Trace, +) -> color_eyre::Report { + let mut message = format!("Error {error}:"); + for context in trace.context.iter().rev() { + write!(message, "\n {}", context).unwrap(); + } + color_eyre::Report::msg(message) +} + macro_rules! load { ($fs:ident, $type:ident) => { RefCell::new(rpg::$type {