Skip to content

Design note: sheet rules as values (Value<T> token references; Sheet/Style PartialEq, serde) #488

Open

Description

@samitbasu

From a consumer, checked against main aa55826. Adopted by the user (2026-11-23) as a design note for approval, after #482. No code before the note is approved.

Today: a rule body is Arc<dyn Fn(Tw, &Tokens) -> Tw> (sheet.rs:181), a closure only so it can read tokens late. So Sheet compares by pointer (Arc::ptr_eq, :251) and keeps a version counter for the build memo, and Style lost PartialEq in #435. The generated bodies are straight Tw chains. Their only token operations are alpha (gamma_multiply, 340 uses) and colour mix (8).

The idea:

  • Tw's colour, length and text properties hold Value<T> = Lit | Token(TokenRef) | Op(alpha, mix, scale, offset, min-with-literal).
  • A rule body becomes a Tw value; tokens are substituted as resolution's last step.
  • Sheet/Style derive Clone, Debug, PartialEq, Hash (with serde behind a feature), and the pointer equality and version go.
  • A rule_fn escape hatch while migrating, with its uses counted (goal: zero).

What it gives:

  • content equality;
  • themes and App rules in files (hot reload, tweakcn import, a resolved style saved beside goldens);
  • an inspector that names the token.

The note must settle:

Order: after the metric tokens issue and #482, so those sheets are converted once. Relates to #468 (tw!/Tw::parse, which would produce values directly).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions