Skip to content

Commit

Permalink
core: add support for recording 128-bit integers (#2166)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
davidbarsky authored and hawkw committed Jun 22, 2022
1 parent 7acf286 commit 36ca66c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 36ca66c

Please sign in to comment.