Skip to content

Commit

Permalink
core: implement field::ValidLen for slices
Browse files Browse the repository at this point in the history
There used to be a length restriction on the arrays usable to construct
`ValueSet`s, but this was due to Rust compiler limitations that no
longer exist. After that restriction was removed, the `ValidLen` trait
was kept around but implemented for statically-sized arrays of all
lengths.

While in theory this allows `ValueSet`s to be constructed from arrays of
arbitrary length, the size of the arrays must still be known at compile
time. Now that there is no longer a restriction on the length of arrays,
slices could in theory be used as well (since they meet the supertrait
requirement of `ValidLen`), but no implementation of the trait exists.

Adding an implementation of `ValidLen` for slices is straightforward.

Refs: tokio-rs#2508
  • Loading branch information
maddiemort committed Nov 3, 2023
1 parent c4b2a56 commit 6e608bd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ mod private {
pub trait ValidLen<'a>: Borrow<[(&'a Field, Option<&'a (dyn Value + 'a)>)]> {}

impl<'a, const N: usize> ValidLen<'a> for [(&'a Field, Option<&'a (dyn Value + 'a)>); N] {}
impl<'a> ValidLen<'a> for &[(&'a Field, Option<&'a (dyn Value + 'a)>)] {}
}

#[cfg(test)]
Expand Down

0 comments on commit 6e608bd

Please sign in to comment.