Use `ReadOnly` in `TryFromBytes::is_bit_valid` by joshlf · Pull Request #2873 · google/zerocopy
Previously, `is_bit_valid` had the signature: ```rust fn is_bit_valid<A>(c: Ptr<'_, Self, (A, Unaligned, Initialized)>) -> bool ``` In this commit, we remove the `A` aliasing parameter and wrap `Self` in `ReadOnly`, yielding: ```rust fn is_bit_valid(c: Ptr<'_, ReadOnly<Self>, (Shared, Unaligned, Initialized)>) -> bool ``` This ensures that `is_bit_valid`'s argument is always uconditionally `Immutable` regardless of whether `Self: Immutable`. This solves a number of open problems: - Ensures that `is_bit_valid` can never mutate its referent (#1831), which is important for custom validators (#1330) - Makes it so that custom validators can be written without needing to be generic over aliasing, which in turn means we can support custom validators without exposing much of our `Ptr` machinery in our public API - Allows us to support `#[derive(TryFromBytes)]` on unions without requiring `Self: Immutable` (#1832) - Permits `T -> U` fallible transmutation in more cases (see #2336 for more details) Makes progress on #2336 gherrit-pr-id: G7691845b6b02e9f3d9578435d732bacfa6ca674f