-
If I have a struct with several u8 and I want to panic during reading if one of the values is outside an arbitrary range (i, j), how would I accomplish this? More generally how can we enforce data meets any criteria? |
Beta Was this translation helpful? Give feedback.
Answered by
csnover
Aug 15, 2023
Replies: 1 comment 1 reply
-
The assert directive validates objects and fields after they are read or before they are written, returning an error if the assertion condition evaluates to false. Any earlier field or import can be referenced by expressions in the directive. For this specific case you would assert on |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JiveyGuy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The assert directive validates objects and fields after they are read or before they are written, returning an error if the assertion condition evaluates to false. Any earlier field or import can be referenced by expressions in the directive.
For this specific case you would assert on
#[br(assert((i..j).contains(field)))]
.