From d36d4bda8623d55ff98976153cf6268fc56b15e7 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sun, 26 Nov 2023 15:07:58 +0100 Subject: [PATCH] feat: adding ron --- Cargo.lock | 28 ++++++++++++++++++++++++++++ Cargo.toml | 3 ++- src/lib.rs | 32 ++++++++++++++++++++------------ 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24b844a..cf769cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +dependencies = [ + "serde", +] + [[package]] name = "colored" version = "2.0.0" @@ -68,6 +83,7 @@ dependencies = [ "anyhow", "colored", "pretty_assertions", + "ron", "serde", "serde_json", "serde_yaml", @@ -147,6 +163,18 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64", + "bitflags", + "serde", + "serde_derive", +] + [[package]] name = "ryu" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index 4a569cb..ddb6418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ edition = "2018" all-features = true [features] -default = ["serde_yaml", "serde_json", "colored", "graphemes_support", "toml"] +default = ["serde_yaml", "serde_json", "colored", "graphemes_support", "toml", "ron"] graphemes_support = ["unicode-segmentation"] [dependencies] @@ -30,6 +30,7 @@ serde = { version = "1", features = ["derive"] } serde_yaml = { version = "0.8", optional = true } unicode-segmentation = { version = "1", optional = true } toml = { version = "0.5", optional = true } +ron = { version = "0.8", optional = true } [dev-dependencies] anyhow = "1" diff --git a/src/lib.rs b/src/lib.rs index 00481e1..7ece8bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,11 +120,7 @@ use colored::Colorize; use std::{ fmt, - sync::atomic::{ - AtomicBool, - AtomicUsize, - Ordering, - }, + sync::atomic::{AtomicBool, AtomicUsize, Ordering}, }; #[cfg(feature = "colored")] @@ -134,13 +130,7 @@ mod control; mod test; #[cfg(feature = "colored")] -pub use control::{ - always_color, - never_color, - set_coloring_mode, - use_environment, - ColoringMode, -}; +pub use control::{always_color, never_color, set_coloring_mode, use_environment, ColoringMode}; /// If the output should be contextualized or not. pub const CONTEXTUALIZE_DEFAULT: bool = true; @@ -232,6 +222,10 @@ pub enum ErrorTypes { /// Contains [`toml::de::Error`]. Toml(toml::de::Error), + #[cfg(feature = "ron")] + /// Contains [`ron::de::Error`]. + Ron(ron::error::SpannedError), + /// Used for custom errors that don't come from serde_yaml or /// serde_json. Custom { @@ -273,6 +267,13 @@ impl From for ErrorTypes { } } +#[cfg(feature = "ron")] +impl From for ErrorTypes { + fn from(err: ron::de::SpannedError) -> Self { + Self::Ron(err) + } +} + impl From<(Box, Option, Option)> for ErrorTypes { fn from(value: (Box, Option, Option)) -> Self { Self::Custom { @@ -313,6 +314,13 @@ impl SerdeError { Some((line, column)) => (e.to_string(), Some(line + 1), Some(column)), }, + #[cfg(feature = "ron")] + ErrorTypes::Ron(e) => ( + e.code.to_string(), + Some(e.position.line), + Some(e.position.col), + ), + ErrorTypes::Custom { error, line,