@@ -641,17 +641,19 @@ impl<'a> Formatter<'a> {
641641// The template byte sequence is the concatenation of parts of the following types:
642642//
643643// - Literal string piece (1-127 bytes):
644+ // Pieces that must be formatted verbatim (e.g. "hello " and "\n" in "hello {name}\n")
645+ // are represented as a single byte containing their length followed directly by the bytes
646+ // of the string:
644647// ┌───┬────────────────────────────┐
645648// │len│ `len` bytes (utf-8) │ (e.g. b"\x06hello ")
646649// └───┴────────────────────────────┘
647- // Pieces that must be formatted verbatim (e.g. "hello " and "\n" in "hello {name}\n")
648- // are represented as a single byte containing their length followed directly by the bytes
649- // of the string.
650650//
651- // Pieces can be 127 bytes at most. Longer pieces are split into multiple pieces (at utf-8
652- // boundaries).
651+ // These strings can be 127 bytes at most, such that the `len` byte always has the highest
652+ // bit cleared. Longer pieces are split into multiple pieces (at utf-8 boundaries).
653653//
654654// - Placeholder:
655+ // Placeholders (e.g. `{name}` in "hello {name}") are represented as a byte with the highest
656+ // bit set, followed by zero or more fields depending on the flags set in the first byte:
655657// ┌──────────┬┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┬┄┄┄┄┄┄┄┄┄┄┄┬┄┄┄┄┄┄┄┄┄┄┄┬┄┄┄┄┄┄┄┄┄┄┄┐
656658// │0b10______│ flags ┊ width ┊ precision ┊ arg_index ┊ (e.g. b"\x82\x05\0")
657659// └────││││││┴┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┴┄┄┄┄┄┄┄┄┄┄┄┴┄┄┄┄┄┄┄┄┄┄┄┴┄┄┄┄┄┄┄┄┄┄┄┘
@@ -663,14 +665,14 @@ impl<'a> Formatter<'a> {
663665// │└─ width indirect
664666// └─ precision indirect
665667//
666- // Fully default placeholder, without any options:
668+ // All fields other than the first byte are optional and only present when
669+ // their corresponding flag is set in the first byte.
670+ //
671+ // So, a fully default placeholder without any options is just a single byte:
667672// ┌──────────┐
668673// │0b10000000│ (b"\x80")
669674// └──────────┘
670675//
671- // Placeholders (e.g. `{name}` in "hello {name}") are represented as a byte with the highest
672- // bit set, followed by zero or more fields depending on the flags set in the first byte.
673- //
674676// The fields are stored as little endian.
675677//
676678// The `flags` fields corresponds to the `flags` field of `FormattingOptions`.
@@ -691,10 +693,10 @@ impl<'a> Formatter<'a> {
691693// at 0).
692694//
693695// - End:
696+ // A single zero byte marks the end of the template:
694697// ┌───┐
695698// │ 0 │ ("\0")
696699// └───┘
697- // A single zero byte marks the end of the template.
698700//
699701// (Note that a zero byte may also occur naturally as part of the string pieces or flags,
700702// width, precision and arg_index fields above. That is, the template byte sequence ends
0 commit comments