You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow types to specify custom valid byte patterns.
The optional-numeric-index crate provides macros to create custom types to index e.g. vectors. These come in pairs, where one is the normal index type and one is an optional index type. For a compact representation, the bit-pattern that corresponds to the maximum value of the index is reserved for a None value. Hence, it is invalid for the normal index type.
Currently, zerocopy has no way of handling that, as it does not allow to manually restrict the valid bit-patterns of a type. Deriving TryFromBytes for one of these custom index types would allow the maximum value as a valid bit pattern. What our project would need is a way to pass a filter function to #[derive(TryFromBytes)] that can reject bit patterns as needed.
Activity
joshlf commentedon Feb 16, 2026
Sounds like you're describing "custom validators", which we're tracking in #1330. Feel free to re-open if that doesn't address what you need!
TryFromBytes#1330