-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass slices into FieldSet::value_set instead of array references #782
Comments
The reason this method takes arrays rather than slices is in order to validate that their lengths are less than 32 elements statically. This is used to emit an error from the macros at compile time when too many fields are passed. However, the fields are stored as a slice internally: tracing/tracing-core/src/field.rs Line 85 in c4a6a6d
We could consider adding a separate constructor that takes a slice and validates the length at runtime (either with an assertion or by making the method fallible). This could be used in cases like FFI. We wouldn't want to change the existing method, as the macros would no longer be able to check lengths statically, but it would be fine to add a new one for this use case. What do you think? |
I'd be happy with a separate slice-compatible constructor. It would also be useful to document how to construct a compatible slice; |
For what it's worth, I would also be very interested in this being solved in 0.2, which I see is part of #922. We have an FFI API that exposes event and span calls into tracing. Even after getting dynamic fields working, the 32-field limitation is the next step. From reading the comments for |
What is the reason for the 32-field limit? |
As length validation has been removed in #2508 would that make a difference to allowing slices in 1.x? The
Maybe ValidLen can be implemented for all slices instead of just arrays with fixed size. |
Feature Request
Motivation
I'm trying to write FFI wrapper methods around
tracing
, and the simplest API is to pass a slice of values across as(values: *const *const c_char, len: usize)
. However,FieldSet::value_set
takes a reference to a fixed-size array, and it isn't possible to generically construct aValueSet
(or have more than 32 fields when not using the macro).Proposal
Change:
to
(or the correct variant of this, as defined by people who actually know how this is used by the rest of the
tracing
internals 😄).Alternatives
TryInto
from the slice to a fixed-size array.message
.[T; 32]
inside the FFI method, and fill in unused positions with(placeholder_field, None)
.The text was updated successfully, but these errors were encountered: