From 3cad70d6a0cacd71017d2f733c2efb94595cf23a Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 17 Jun 2022 18:21:32 -0400 Subject: [PATCH] core: add support for recording 128-bit integers (#2166) ## Motivation I've received a request at work to record 128-bit integers and realized that we should probably support recording them. ## Solution Added two methods to the `Visit` trait, `record_i128` and `record_u128`. However, I didn't add the size conversions present for 64-bit integers, as 128-bit integers are, at this time, more specialized. --- tracing-core/src/field.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index df67566cda..c9869ce2ca 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -16,9 +16,9 @@ //! will contain any fields attached to each event. //! //! `tracing` represents values as either one of a set of Rust primitives -//! (`i64`, `u64`, `f64`, `bool`, and `&str`) or using a `fmt::Display` or -//! `fmt::Debug` implementation. `Subscriber`s are provided these primitive -//! value types as `dyn Value` trait objects. +//! (`i64`, `u64`, `f64`, `i128`, `u128`, `bool`, and `&str`) or using a +//! `fmt::Display` or `fmt::Debug` implementation. `Subscriber`s are provided +//! these primitive value types as `dyn Value` trait objects. //! //! These trait objects can be formatted using `fmt::Debug`, but may also be //! recorded as typed data by calling the [`Value::record`] method on these @@ -278,6 +278,16 @@ pub trait Visit { self.record_debug(field, &value) } + /// Visit a signed 128-bit integer value. + fn record_i128(&mut self, field: &Field, value: i128) { + self.record_debug(field, &value) + } + + /// Visit an unsigned 128-bit integer value. + fn record_u128(&mut self, field: &Field, value: u128) { + self.record_debug(field, &value) + } + /// Visit a boolean value. fn record_bool(&mut self, field: &Field, value: bool) { self.record_debug(field, &value) @@ -490,6 +500,8 @@ impl_values! { record_u64(usize, u32, u16, u8 as u64), record_i64(i64), record_i64(isize, i32, i16, i8 as i64), + record_u128(u128), + record_i128(i128), record_bool(bool), record_f64(f64, f32 as f64) }