Skip to content

Bounds written on types: T[a..b], string[..n] #98

Closed

Description

@Kinflou

Allow bounds written directly on a type: T[1..10], T[..10], string[..64] (syntax open).

How this differs from validators

Bounds on the type Validators
What they express the shape of the data rules about values
Effect on generated types can change them ([T; N], a fixed-capacity string) none
When they're enforced always, while decoding when validate() runs, or on decode if opted in
Safety the decoder can refuse an oversized length before allocating only after the value is fully decoded
Wire and size a fixed T[N] may omit the length prefix; size.rs can compute sizes no effect
Changing them later wire-relevant: tightening breaks old senders, loosening breaks old receivers a behaviour change only

The main reason to have these is the maximum: it protects decoders from huge allocations, which a validator can't do. Minimums can live in either place.

Points to settle

  • Unit for string bounds: UTF-8 bytes, because the bound exists for decoder safety and allocation. Validators count Unicode scalar values (Validators declare the types they apply to #97). These are different rules, and the docs should say so.
  • Contradictions: string[..10] combined with StringBounds(min_chars = 20) can never pass, so core should reject it at build. Optionally, warn when a validator only repeats a bound.
  • Aliases: type AccountName = string[1..32] carries the bound in its type, and validators on the alias add rules on top.
  • Fixed-size representation: a bounded string lets a generator emit a fixed-capacity, non-heap string if it chooses to. That is the generator's decision, not a schema or comline.toml setting.
  • Schema evolution: whatever compares schema versions should treat a bound change as wire-relevant.

Depends on

Activity

  1. added
    1.0-blockerMust be done before the 1.0 announcement (docs conduct/readiness.md)
    P1Next
    and removed
    P2Soon
    on Oct 31, 2026
  2. added this to the 1.0 milestone on Oct 31, 2026
  3. added a commit that references this issue on Nov 3, 2026
  4. Kinflou commented on Nov 9, 2026

    @Kinflou
    MemberAuthor

    Complete: steps 1–10 are merged across core (#191–#196, #200), runtime#78, generation#110/#112/#114–#116, comline-rust#100/#101/#104, comline-typescript#122/#124–#127, cli#130, language-server#97 and playground#111. The one leftover, checking worst-case encoded sizes against the configured frame limits, is tracked in #202.

  5. moved this from Todo to Done in Comline Development Roadmapon Nov 9, 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

    1.0-blockerMust be done before the 1.0 announcement (docs conduct/readiness.md)P1NextcompilerParser, IR, CASenhancementNew feature or request

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions