Expand description
Part
s are used as annotations for formatted strings. For example, a string like
Alice, Bob
could assign a NAME
part to the substrings Alice
and Bob
, and a
PUNCTUATION
part to ,
. This allows for example to apply styling only to names.
Part
contains two fields, whose usage is left up to the producer of the Writeable
.
Conventionally, the category
field will identify the formatting logic that produces
the string/parts, whereas the value
field will have semantic meaning. NAME
and
PUNCTUATION
could thus be defined as
const NAME: Part = Part {
category: "userlist",
value: "name",
};
const PUNCTUATION: Part = Part {
category: "userlist",
value: "punctuation",
};
That said, consumers should not usually have to inspect Part
internals. Instead,
formatters should expose the Part
s they produces as constants.
Fields§
§category: &'static str
§value: &'static str