From 021e3025751d3b23efb30e16326d02d2dfab349c Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 28 Jun 2023 23:22:06 -0500 Subject: [PATCH] Clarify that all fields are usable in BinWrite directives Closes jam1garner/binrw#208. --- binrw/doc/attribute.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/binrw/doc/attribute.md b/binrw/doc/attribute.md index 4a597f96..7b7641ef 100644 --- a/binrw/doc/attribute.md +++ b/binrw/doc/attribute.md @@ -134,7 +134,8 @@ argument of a [`BinWrite::write_options`](crate::BinWrite::write_options) call, respectively. -Any earlier field or [import](#arguments) can be referenced in `args`. +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced in `args`. ## Ways to pass and receive arguments @@ -429,7 +430,8 @@ executed in order. Assertions added to the top of an enum will be checked against every variant in the enum. -Any earlier field or [import](#arguments) can be referenced by expressions +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced by expressions in the directive. ## Examples @@ -643,7 +645,9 @@ a struct field: The `is_big` and `is_little` directives are primarily useful when byte order -is defined in the data itself. Any earlier field or [import](#arguments) can +is defined in the data itself. Any +(earlier only, when reading)earlier +field or [import](#arguments) can be referenced in the condition. Conditional byte order directives can only be used on struct fields. @@ -819,8 +823,9 @@ a struct field: ``` -Any earlier field or [import](#arguments) can be -referenced by the expression in the directive. +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced by the expression in the +directive. When using `try_calc`, the produced value must be a [`Result`](Result). @@ -940,7 +945,8 @@ The alternate expression is not evaluated unless the condition is false, so it is safe for it to contain expensive operations without impacting performance. -Any earlier field or [import](#arguments) can be referenced by the +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced by the expression in the directive. The [`map`](#map) directive can also be used to conditionally @@ -1606,7 +1612,8 @@ and must return a type that implements [`BinWrite`](crate::BinWrite) for will receive an immutable reference to the entire object and must return a type that implements [`BinWrite`](crate::BinWrite). -Any earlier field or [import](#arguments) can be +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced by the expression in the directive. ## Examples @@ -1930,7 +1937,8 @@ read the string and `pad_size_to(256)` will ensure the reader skips whatever padding, if any, remains. If the string is longer than 256 bytes, no padding will be skipped. -Any earlier field or [import](#arguments) can be +Any (earlier only, when reading)earlier +field or [import](#arguments) can be referenced by the expressions in any of these directives. ## Examples