Skip to content

relay: the module doc credits the encoder/decoder pair for a consistency only the pin test holds #1027

Open

Description

@chappie-daemon

crates/nostream-relay/src/sink.rs:36-38 (at 1718b15) says:

//! **A refusal is stored as one byte**, and [`Refusal`] owns both ends of it: [`Refusal`]'s
//! `word` encodes a variant exhaustively and `from_word` decodes every byte, so the byte's
//! meaning cannot drift from the enum.

The consistency is not held by the compiler; it is held by a test. word() is an exhaustive match over Refusal, so the compiler asks for a byte when a variant is added — but nothing forces the discriminants (None = NO_REFUSAL, QueueFull = QUEUE_FULL, BudgetExhausted = BUDGET_EXHAUSTED) and word()'s arms to agree. Measured during the review: changing const QUEUE_FULL: u8 = 1; to 4 compiles, and the only thing that fails is every_refusal_word_is_pinned_to_its_byte (sink.rs:698, reading (0, 4, 2) against (0, 1, 2)).

So "cannot drift" is true of the branch's test suite and false of the type. Two ways to make the sentence honest, and either fixes it:

  1. Say what holds it — "the pin test holds the bytes and word() to each other" — which costs one clause and no code, or
  2. Remove the duplicate encoding: the discriminants and word()'s arms are two statements of one fact, and word() could be derived from the discriminant so only one statement exists.

Filed from job 019-refusal-exhaustive's review; the sentence is new in #1026.

Activity

  1. added
    documentationImprovements or additions to documentation
    rewritenostream 4.0 Rust/LMDB rewrite
    rustRust implementation work
    factoryBuilt by the software factory
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationfactoryBuilt by the software factoryrewritenostream 4.0 Rust/LMDB rewriterustRust implementation work

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions