Skip to content

Commit

Permalink
Move ErrorRef wrapping logic to __slog_builtin!
Browse files Browse the repository at this point in the history
Avoids duplicating multiple times across multiple macros.

Explicitly suppress unused_import warning (needed with clippy deny warnings)
  • Loading branch information
Techcable committed Jan 3, 2024
1 parent 25c0b12 commit f672095
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ macro_rules! kv(
kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@format_args "{:#?}", $v))), $args_ready); $($args)* )
};
(@ $args_ready:expr; $k:expr => #$v:expr) => {
kv!(@ ($crate::SingleKV::from(($k, { use $crate::{ErrorRefKind, ErrorValueKind}; let v = $v; let w = $crate::ErrorTagWrapper(v); (&&w).slog_error_kind().wrap(w.0) } )), $args_ready); )
kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@wrap_error $v) )), $args_ready); )
};
(@ $args_ready:expr; $k:expr => #$v:expr, $($args:tt)* ) => {
kv!(@ ($crate::SingleKV::from(($k, { use $crate::{ErrorRefKind, ErrorValueKind}; let v = $v; let w = $crate::ErrorTagWrapper(v); (&&w).slog_error_kind().wrap(w.0) } )), $args_ready); $($args)* )
kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@wrap_error $v))), $args_ready); $($args)* )
};
(@ $args_ready:expr; $k:expr => $v:expr) => {
kv!(@ ($crate::SingleKV::from(($k, $v)), $args_ready); )
Expand Down Expand Up @@ -462,10 +462,10 @@ macro_rules! slog_kv(
slog_kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@format_args "{:#?}", $v))), $args_ready); $($args)* )
};
(@ $args_ready:expr; $k:expr => #$v:expr) => {
slog_kv!(@ ($crate::SingleKV::from(($k, { use $crate::{ErrorRefKind, ErrorValueKind}; let v = $v; let w = $crate::ErrorTagWrapper(v); (&&w).slog_error_kind().wrap(w.0) } )), $args_ready); )
slog_kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@wrap_error $v) )), $args_ready); )
};
(@ $args_ready:expr; $k:expr => #$v:expr, $($args:tt)* ) => {
slog_kv!(@ ($crate::SingleKV::from(($k, { use $crate::{ErrorRefKind, ErrorValueKind}; let v = $v; let w = $crate::ErrorTagWrapper(v); (&&w).slog_error_kind().wrap(w.0) } )), $args_ready); $($args)* )
slog_kv!(@ ($crate::SingleKV::from(($k, __slog_builtin!(@wrap_error $v) )), $args_ready); $($args)* )
};
(@ $args_ready:expr; $k:expr => $v:expr) => {
slog_kv!(@ ($crate::SingleKV::from(($k, $v)), $args_ready); )
Expand Down Expand Up @@ -1068,6 +1068,16 @@ macro_rules! __slog_builtin {
(@line) => ( line!() );
(@column) => ( column!() );
(@module_path) => ( module_path!() );
(@wrap_error $v:expr) => ({
// this magical sequence of code is used to wrap either with
// slog::ErrorValue or slog::ErrorRef as appropriate
// See PR #328 for details
#[allow(unused_imports)]
use $crate::{ErrorRefKind, ErrorValueKind};
let v = $v;
let w = $crate::ErrorTagWrapper(v);
(&&w).slog_error_kind().wrap(w.0)
});
}

// }}}
Expand Down

0 comments on commit f672095

Please sign in to comment.