Skip to content

Commit

Permalink
Implement ValidLen for all sizes of arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
eopb committed Mar 14, 2023
1 parent a0126b2 commit 5329124
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
25 changes: 2 additions & 23 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,6 @@ impl FieldSet {
}

/// Returns a new `ValueSet` with entries for this `FieldSet`'s values.
///
/// Note that a `ValueSet` may not be constructed with arrays of over 32
/// elements.
#[doc(hidden)]
pub fn value_set<'v, V>(&'v self, values: &'v V) -> ValueSet<'v>
where
Expand Down Expand Up @@ -933,28 +930,10 @@ impl<'a> fmt::Display for ValueSet<'a> {
mod private {
use super::*;

/// Marker trait implemented by arrays which are of valid length to
/// construct a `ValueSet`.
///
/// `ValueSet`s may only be constructed from arrays containing 32 or fewer
/// elements, to ensure the array is small enough to always be allocated on the
/// stack. This trait is only implemented by arrays of an appropriate length,
/// ensuring that the correct size arrays are used at compile-time.
/// Restrictions on `ValueSet` lengths were removed in #2508 but this type remains for backwards compatibility.
pub trait ValidLen<'a>: Borrow<[(&'a Field, Option<&'a (dyn Value + 'a)>)]> {}
}

macro_rules! impl_valid_len {
( $( $len:tt ),+ ) => {
$(
impl<'a> private::ValidLen<'a> for
[(&'a Field, Option<&'a (dyn Value + 'a)>); $len] {}
)+
}
}

impl_valid_len! {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
impl<'a, const N: usize> ValidLen<'a> for [(&'a Field, Option<&'a (dyn Value + 'a)>); N] {}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! override their default values.
//! - The span's [verbosity level]
//! - A string literal providing the span's name.
//! - Finally, between zero and 32 arbitrary key/value fields.
//! - Finally, zero or more arbitrary key/value fields.
//!
//! [`target`]: super::Metadata::target()
//!
Expand Down

0 comments on commit 5329124

Please sign in to comment.