flm_core/stdlib/features/numbering/writer.rs
1//! The number writer, which turns counter values into the content a reader
2//! sees, and the context it writes with.
3//!
4//! A counter style says what a number is made of: the word before it, the
5//! delimiters, the number format, the texts that join several numbers. The
6//! **number writer** puts those texts and numbers together: it receives the values to
7//! write and appends the content they are shown as. One writer is built in,
8//! the **default writer**, which writes what the counter style's data
9//! describes; a feature may register another writer by name, and a counter
10//! style may ask for it
11//! ([`CounterStyleDecl::with_number_writer`](super::CounterStyleDecl::with_number_writer)).
12//!
13//! A number writer exists in two forms, as a declaration and as a compiled
14//! value, as a [within-joiner](super::WithinJoiner) does. [`NumberWriter`] is
15//! the declaration: a name, and a method that compiles the writer once the
16//! language is built, when the writer parses the markup of its own texts.
17//! [`CompiledNumberWriter`] is the compiled writer, with two entry points: one
18//! value, and several values of one counter style.
19//!
20//! For each value, a writer receives a [`NumberedValue`] (the counter value
21//! and the counters it is numbered within), together with the caller's
22//! [`FormatOptions`] and a [`WriteCx`], the writing context that holds the
23//! counter style's data and the library's operations. The writer appends what
24//! it writes to a [`NumberOut`], item by item, each item marked with the
25//! value it links to or with none; the library merges neighboring items of
26//! one link into the [`Segment`](super::Segment)s that the caller receives.
27//!
28//! The parts written for the counters a number is numbered within are
29//! computed **on demand**: [`WriteCx::parts`] runs the value's within-joiner
30//! and returns its [`Part`]s. A writer that arranges the ancestors itself
31//! never calls it, and the within-joiner is then never run. The parts of one
32//! list of ancestors are computed once per call and kept for the rest of it.
33
34use std::cell::RefCell;
35use std::collections::BTreeMap;
36use std::fmt;
37use std::sync::{Arc, OnceLock};
38
39use techy::core::node::NodeTree;
40
41use crate::lang::{BuiltLang, Flm};
42use crate::model::addr::NodeAddr;
43use crate::model::names::Name;
44
45use super::formats::NumberFormat;
46use super::joiner::{JoinCx, Part};
47use super::many::default_many;
48use super::style::{
49 default_one, number_tree, parse_text, Ancestor, CounterStyle, FormatError, FormatOptions,
50 Item, Mark, Parent, Piece, StyleError,
51};
52use super::value::CounterValue;
53
54// --- what a writer is asked to write ------------------------------------------------------
55
56/// One value that a number writer is asked to write: the counter value, the
57/// counters it is numbered within, the scoped instance it was counted in if
58/// any, and its position among the values the caller passed in.
59///
60/// The position is what the link mark of a written item carries: `0` for the
61/// only value of [`format`](super::format), and the position in the caller's
62/// list for [`format_many`](super::format_many). The library sets it; a caller
63/// builds a value with [`new`](NumberedValue::new) and, where the counter is
64/// numbered within others, [`within`](NumberedValue::within).
65#[derive(Clone, Copy, Debug)]
66pub struct NumberedValue<'a> {
67 value: &'a CounterValue,
68 parent: Option<Parent<'a>>,
69 instance: Option<NodeAddr>,
70 index: usize,
71}
72
73impl<'a> NumberedValue<'a> {
74 /// Returns `value`, numbered within nothing and counted in no scoped
75 /// instance.
76 pub fn new(value: &'a CounterValue) -> NumberedValue<'a> {
77 NumberedValue { value, parent: None, instance: None, index: 0 }
78 }
79
80 /// Builder: this value is numbered within `parent`, which holds the
81 /// within-joiner that writes the ancestors' numbers and the ancestors
82 /// themselves.
83 pub fn within(mut self, parent: Parent<'a>) -> NumberedValue<'a> {
84 self.parent = Some(parent);
85 self
86 }
87
88 /// Builder: this value was counted in the scoped instance attached to the
89 /// node `instance` (see
90 /// [`NumberSource::instances`](crate::model::aspects::NumberSource::instances)).
91 ///
92 /// Values of two different instances belong to two different sequences of
93 /// the counter, so the default writer never groups them together,
94 /// regardless of their ancestors: the first items of two sibling lists
95 /// are `1` and `1`, never a range.
96 pub fn in_instance(mut self, instance: NodeAddr) -> NumberedValue<'a> {
97 self.instance = Some(instance);
98 self
99 }
100
101 /// Returns the scoped instance this value was counted in, or `None` for a
102 /// value of the counter's single sequence through the document.
103 pub fn instance(&self) -> Option<NodeAddr> {
104 self.instance
105 }
106
107 /// Returns the counter value itself.
108 pub fn value(&self) -> &'a CounterValue {
109 self.value
110 }
111
112 /// Returns the counters this value is numbered within, outermost first,
113 /// or an empty list for a counter numbered within nothing.
114 pub fn ancestors(&self) -> &'a [Ancestor] {
115 match &self.parent {
116 Some(parent) => parent.ancestors,
117 None => &[],
118 }
119 }
120
121 /// Returns the position of this value among the values the caller passed
122 /// in, which a link mark carries.
123 pub fn index(&self) -> usize {
124 self.index
125 }
126
127 /// Returns the within-joiner and the ancestors, as the library recorded
128 /// them.
129 pub(super) fn parent(&self) -> Option<Parent<'a>> {
130 self.parent
131 }
132
133 /// Returns this value at position `index` among the caller's values.
134 pub(super) fn at(mut self, index: usize) -> NumberedValue<'a> {
135 self.index = index;
136 self
137 }
138}
139
140// --- what a writer writes into ------------------------------------------------------------
141
142/// The output to which a number writer appends what it writes.
143///
144/// A writer appends content ([`content`](NumberOut::content)) or characters
145/// ([`text`](NumberOut::text)), each marked with the position of the value it
146/// links to, or with `None` for an item that is part of no link. The library
147/// merges neighboring items that carry the same mark and turns each merged
148/// sequence into one [`Segment`](super::Segment); an item that holds no
149/// content and links to nothing is left out.
150pub struct NumberOut<'a> {
151 items: Vec<Item<'a>>,
152}
153
154impl<'a> NumberOut<'a> {
155 /// Returns an empty output.
156 pub(super) fn new() -> NumberOut<'a> {
157 NumberOut { items: Vec::new() }
158 }
159
160 /// Appends `content`, linking to the value at `link` among the caller's
161 /// values, or to nothing.
162 pub fn content(&mut self, content: Arc<NodeTree<Flm>>, link: Option<usize>) {
163 self.items.push(Item { pieces: vec![Piece::Tree(content)], mark: mark_of(link) });
164 }
165
166 /// Appends `text` as characters, linking to the value at `link` among the
167 /// caller's values, or to nothing.
168 ///
169 /// The characters become one text node when the result is assembled;
170 /// [`WriteCx::literal`] builds the same content for a writer that needs
171 /// the content itself.
172 pub fn text(&mut self, text: &str, link: Option<usize>) {
173 self.items.push(Item { pieces: vec![Piece::Digits(text.to_string())], mark: mark_of(link) });
174 }
175
176 /// Appends one item of the library's own, which may carry a mark that
177 /// joins it to the link of its neighbors, if any.
178 pub(super) fn item(&mut self, item: Item<'a>) {
179 self.items.push(item);
180 }
181
182 /// Appends several items of the library's own.
183 pub(super) fn items(&mut self, items: impl IntoIterator<Item = Item<'a>>) {
184 self.items.extend(items);
185 }
186
187 /// Returns everything that was appended, in order.
188 pub(super) fn into_items(self) -> Vec<Item<'a>> {
189 self.items
190 }
191}
192
193impl fmt::Debug for NumberOut<'_> {
194 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
195 f.debug_struct("NumberOut").field("pieces", &self.items.len()).finish()
196 }
197}
198
199/// Returns the mark that a caller's link position gives.
200fn mark_of(link: Option<usize>) -> Mark {
201 match link {
202 Some(index) => Mark::Value(index),
203 None => Mark::Never,
204 }
205}
206
207// --- the two traits -----------------------------------------------------------------------
208
209/// A number writer as a feature declares it: its name, and how it compiles
210/// itself once the language is built.
211///
212/// A feature contributes a writer, wrapped in a [`NumberWriterDecl`], to the
213/// service slot [`NUMBER_WRITERS_SLOT`](super::NUMBER_WRITERS_SLOT), and a
214/// counter style asks for it by name with
215/// [`CounterStyleDecl::with_number_writer`](super::CounterStyleDecl::with_number_writer).
216/// Two writers of one name fail the registry build, and so does a counter
217/// style that asks for a writer no feature registers. The [numbering module
218/// documentation](super#the-number-writer) describes what a writer receives
219/// and writes.
220pub trait NumberWriter: Send + Sync {
221 /// Returns the name by which counter styles ask for this writer. It is
222 /// dotted and owned by the feature that declares it, such as
223 /// `example.numbering.in-section`, as a counter style's name is.
224 fn name(&self) -> &Name;
225
226 /// Returns this writer compiled against the built language, which `cx`
227 /// holds; every text of the writer's own is parsed here. The library
228 /// compiles a writer once per counter style that asks for it, when the
229 /// registry is built.
230 ///
231 /// # Errors
232 ///
233 /// The [`StyleError`] of a text of the writer's own that is not valid FLM.
234 fn compile(&self, cx: &WriterCx<'_>) -> Result<Arc<dyn CompiledNumberWriter>, StyleError>;
235}
236
237/// A number writer as it is contributed to the service slot
238/// [`NUMBER_WRITERS_SLOT`](super::NUMBER_WRITERS_SLOT): a value that holds the
239/// writer.
240///
241/// A service slot hands out its values as borrowed references, and the
242/// numbering feature uses a writer long after the registry build has released
243/// them, so the service slot holds this value, of which the numbering feature
244/// keeps a copy.
245#[derive(Clone)]
246pub struct NumberWriterDecl {
247 writer: Arc<dyn NumberWriter>,
248}
249
250impl NumberWriterDecl {
251 /// Returns the declaration of `writer`.
252 pub fn new(writer: Arc<dyn NumberWriter>) -> NumberWriterDecl {
253 NumberWriterDecl { writer }
254 }
255
256 /// Returns the writer it holds.
257 pub fn writer(&self) -> &Arc<dyn NumberWriter> {
258 &self.writer
259 }
260}
261
262impl fmt::Debug for NumberWriterDecl {
263 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264 f.debug_struct("NumberWriterDecl").field("name", &self.writer.name().as_str()).finish()
265 }
266}
267
268/// A compiled number writer: what writes the numbers of a counter style.
269///
270/// The two entry points are the two ways a number is asked for. One value
271/// comes through [`format`](super::format), which a construct showing its own
272/// number and a reference to one point use. Several values of one counter
273/// style come through [`format_many`](super::format_many), which writes a
274/// reference to several points: the writer receives all of them, with their
275/// ancestors, and decides which of them are written together.
276pub trait CompiledNumberWriter: Send + Sync + fmt::Debug {
277 /// Writes one value into `out`.
278 ///
279 /// # Errors
280 ///
281 /// The [`FormatError`] of any operation the writer asked `cx` for.
282 fn write_one<'a>(
283 &self,
284 value: &NumberedValue<'a>,
285 options: &FormatOptions,
286 cx: &WriteCx<'a>,
287 out: &mut NumberOut<'a>,
288 ) -> Result<(), FormatError>;
289
290 /// Writes several values of one counter style into `out`, in the order the
291 /// writer chooses.
292 ///
293 /// The values come in the caller's order, and each carries its own
294 /// ancestors. The list may be empty; the default writer then writes the
295 /// counter style's text for an empty list ([`JoinText::Empty`]).
296 ///
297 /// # Errors
298 ///
299 /// The [`FormatError`] of any operation the writer asked `cx` for.
300 fn write_many<'a>(
301 &self,
302 values: &[NumberedValue<'a>],
303 options: &FormatOptions,
304 cx: &WriteCx<'a>,
305 out: &mut NumberOut<'a>,
306 ) -> Result<(), FormatError>;
307}
308
309// --- compiling ------------------------------------------------------------------------------
310
311/// The context against which a number writer is compiled: the built language,
312/// and the name of the counter style the writer is compiled for.
313///
314/// A writer is compiled once per counter style that asks for it, when the
315/// registry is built, so a text of its own is parsed then and never again
316/// while a number is written.
317pub struct WriterCx<'a> {
318 lang: &'a BuiltLang,
319 style: &'a Name,
320}
321
322impl<'a> WriterCx<'a> {
323 /// Returns the context over `lang`, for the counter style named `style`.
324 pub(super) fn new(lang: &'a BuiltLang, style: &'a Name) -> WriterCx<'a> {
325 WriterCx { lang, style }
326 }
327
328 /// Returns the built language.
329 pub fn lang(&self) -> &BuiltLang {
330 self.lang
331 }
332
333 /// Returns the name of the counter style this writer is being compiled
334 /// for.
335 pub fn style(&self) -> &Name {
336 self.style
337 }
338
339 /// Returns `text` parsed as FLM, as every text of a counter style is
340 /// parsed. Warnings of the parse are dropped.
341 ///
342 /// # Errors
343 ///
344 /// The [`StyleError`] of a text that is not valid FLM.
345 pub fn parse(&self, text: &str) -> Result<Arc<NodeTree<Flm>>, StyleError> {
346 let mut warnings = Vec::new();
347 parse_text(text, self.lang, &mut warnings)
348 }
349}
350
351// --- the toolbox ------------------------------------------------------------------------------
352
353/// The name of one of the join texts with which a counter style joins
354/// several numbers ([`WriteCx::join_text`]).
355///
356/// The texts are the ones [`JoinDecl`](super::JoinDecl) declares, with its
357/// variables already substituted. A writer decides which of them it uses;
358/// [`JoinDecl`](super::JoinDecl) describes how the default writer uses them.
359#[derive(Clone, Copy, PartialEq, Eq, Debug)]
360pub enum JoinText {
361 /// Before a single run of numbers.
362 OnePre,
363 /// After a single run of numbers.
364 OnePost,
365 /// Before two runs.
366 PairPre,
367 /// Between two runs.
368 PairMid,
369 /// After two runs.
370 PairPost,
371 /// Before a run of several numbers.
372 RangePre,
373 /// Between the ends of a run of three or more.
374 RangeMid,
375 /// Between the ends of a run of exactly two.
376 RangePairMid,
377 /// After a run of several numbers.
378 RangePost,
379 /// Before three runs or more.
380 ListPre,
381 /// Between the runs of a list, except before the last.
382 ListMid,
383 /// Before the last run of a list.
384 ListMidLast,
385 /// After three runs or more.
386 ListPost,
387 /// The text written when there is no number at all.
388 Empty,
389}
390
391/// The writing context of a number writer: the counter style's data, the
392/// library's operations that build content, the within-joiner on demand, and
393/// the default writer to delegate to.
394///
395/// Everything a reader sees is content, not characters, and a writer builds
396/// content only through this context.
397pub struct WriteCx<'a> {
398 style: &'a CounterStyle,
399 /// The parts already written in this call, per chain of ancestors: the
400 /// within-joiner of one chain runs once, however many values are written
401 /// from it.
402 parts: RefCell<BTreeMap<PartsKey, Arc<Vec<Part>>>>,
403}
404
405/// The key that tells one chain of ancestors from another within one call:
406/// the within-joiner that writes them and the list itself, both by address,
407/// since a call writes values from records that do not move while it runs.
408///
409/// The within-joiner's address here is the address of its data alone, without
410/// the table of methods a trait object also carries. Two within-joiners that
411/// hold no data of their own therefore have the same address, so the key
412/// relies on an assumption: two values whose ancestors are the same list, at
413/// the same address, are numbered within it by the same within-joiner. The
414/// assumption holds because a record holds the within-joiner of its counter
415/// beside its chain of ancestors, and the records do not move while the call
416/// runs.
417type PartsKey = (usize, usize, usize);
418
419impl<'a> WriteCx<'a> {
420 /// Returns the writing context over `style`, the counter style in which
421 /// every value of this call is written.
422 pub(super) fn new(style: &'a CounterStyle) -> WriteCx<'a> {
423 WriteCx { style, parts: RefCell::new(BTreeMap::new()) }
424 }
425
426 /// Returns the counter style in which every value of this call is
427 /// written.
428 pub fn style(&self) -> &'a CounterStyle {
429 self.style
430 }
431
432 /// Returns the word written before `count` numbers in the variant
433 /// `variant` of the prefix words, or `None` when that word is the empty
434 /// text and nothing is written. A variant the counter style does not
435 /// declare gives the default words.
436 pub fn word(&self, count: usize, variant: Option<&str>) -> Option<&'a Arc<NodeTree<Flm>>> {
437 self.style.word_text(count, variant)
438 }
439
440 /// Returns the counter style's opening delimiter, the text written before
441 /// a number.
442 pub fn open(&self) -> &'a Arc<NodeTree<Flm>> {
443 self.style.open()
444 }
445
446 /// Returns the counter style's closing delimiter, the text written after
447 /// a number.
448 pub fn close(&self) -> &'a Arc<NodeTree<Flm>> {
449 self.style.close()
450 }
451
452 /// Returns whether the counter style says that the word written before
453 /// several numbers belongs to the link to the first number written. A
454 /// writer that writes a word itself marks it with the position of the first
455 /// number it writes when this is true, and with none when it is false.
456 /// For one value written with [`format`](super::format), the default
457 /// writer makes the whole text one link regardless of this setting.
458 pub fn name_in_link(&self) -> bool {
459 self.style.name_in_link()
460 }
461
462 /// Returns whether the counter style says that the end of a range repeats
463 /// the parts that come from the counters the value is numbered within:
464 /// `A.I–A.III` instead of `A.I–III`. A writer that builds a range itself
465 /// decides with this whether to write the end's parts again.
466 pub fn repeat_parents_in_range(&self) -> bool {
467 self.style.repeat_parents_in_range()
468 }
469
470 /// Returns whether the counter style says that consecutive numbers
471 /// collapse into a range (`1–3`) instead of each being written separately
472 /// (`1,2,3`). A writer that builds ranges itself decides with this whether
473 /// to build any.
474 pub fn ranges(&self) -> bool {
475 self.style.ranges()
476 }
477
478 /// Returns the counter style's join text `which`.
479 pub fn join_text(&self, which: JoinText) -> &'a Arc<NodeTree<Flm>> {
480 self.style.join().text(which)
481 }
482
483 /// Returns `value` written with the counter style's own number template,
484 /// with its sub-numbers: the number alone, with no word, no delimiters and
485 /// nothing of the counters it is numbered within.
486 ///
487 /// # Errors
488 ///
489 /// [`FormatError::UndeclaredSubLevel`] when the value carries a sub-number
490 /// at a level the counter style declares no format for, and a failure to
491 /// build the content.
492 pub fn number(&self, value: &CounterValue) -> Result<Arc<NodeTree<Flm>>, FormatError> {
493 number_tree(self.style, value, None)
494 }
495
496 /// Returns `value` written in `format` instead of with the counter style's
497 /// own number template, its sub-numbers in that format too.
498 ///
499 /// # Errors
500 ///
501 /// The same as [`number`](WriteCx::number).
502 pub fn number_in(
503 &self,
504 value: &CounterValue,
505 format: NumberFormat,
506 ) -> Result<Arc<NodeTree<Flm>>, FormatError> {
507 number_tree(self.style, value, Some(format))
508 }
509
510 /// Returns `ancestor`'s own number, written in the ancestor's own counter
511 /// style: the number alone, with no word, no delimiters and nothing of its
512 /// own ancestors.
513 ///
514 /// # Errors
515 ///
516 /// The same as [`number`](WriteCx::number), for the ancestor's counter
517 /// style.
518 pub fn number_of(&self, ancestor: &Ancestor) -> Result<Arc<NodeTree<Flm>>, FormatError> {
519 number_tree(&ancestor.style, &ancestor.value, None)
520 }
521
522 /// Returns `ancestor`'s own number written in `format` instead of the
523 /// format of its own counter style.
524 ///
525 /// # Errors
526 ///
527 /// The same as [`number`](WriteCx::number), for the ancestor's counter
528 /// style.
529 pub fn number_of_in(
530 &self,
531 ancestor: &Ancestor,
532 format: NumberFormat,
533 ) -> Result<Arc<NodeTree<Flm>>, FormatError> {
534 number_tree(&ancestor.style, &ancestor.value, Some(format))
535 }
536
537 /// Returns `text` as a small tree of content, built as the characters of
538 /// a number are: one text node attributed to the counter style's source.
539 ///
540 /// # Errors
541 ///
542 /// [`FormatError`] when the content could not be built.
543 pub fn literal(&self, text: &str) -> Result<Arc<NodeTree<Flm>>, FormatError> {
544 self.style.literal(text)
545 }
546
547 /// Returns the parts written before `value`'s own number: what its
548 /// [within-joiner](super::WithinJoiner) writes of the counters it is
549 /// numbered within.
550 ///
551 /// The within-joiner runs the first time this method is called for a list
552 /// of ancestors, and its result is kept for the rest of the call: a writer
553 /// that never calls it never runs the within-joiner, and one that calls it
554 /// for two values that share one list of ancestors runs it once. A value
555 /// numbered within nothing has no part.
556 ///
557 /// # Errors
558 ///
559 /// [`FormatError::UnknownAncestor`] when the within-joiner refers to a
560 /// counter that is not in the chain, and a failure to build the content.
561 pub fn parts(&self, value: &NumberedValue<'_>) -> Result<Vec<Part>, FormatError> {
562 let Some(parent) = value.parent() else { return Ok(Vec::new()) };
563 let key: PartsKey = (
564 std::ptr::from_ref(parent.joiner).cast::<()>() as usize,
565 parent.ancestors.as_ptr() as usize,
566 parent.ancestors.len(),
567 );
568 if let Some(written) = self.parts.borrow().get(&key) {
569 return Ok(written.as_ref().clone());
570 }
571 let cx = JoinCx::new(self.style);
572 let written = Arc::new(parent.joiner.parts(parent.ancestors, &cx)?);
573 self.parts.borrow_mut().insert(key, Arc::clone(&written));
574 Ok(written.as_ref().clone())
575 }
576
577 /// Writes `value` into `out` as the default writer would: the word, the
578 /// delimiters, the parts and the number.
579 ///
580 /// A writer calls it to add to the default text instead of replacing it:
581 /// `Eq.~(5)`, followed by ` in Section~V` of its own.
582 ///
583 /// # Errors
584 ///
585 /// The same as [`format`](super::format).
586 pub fn default_one(
587 &self,
588 value: &NumberedValue<'a>,
589 options: &FormatOptions,
590 out: &mut NumberOut<'a>,
591 ) -> Result<(), FormatError> {
592 default_one(value, options, self, out)
593 }
594
595 /// Writes `values` into `out` as the default writer would: grouped by the
596 /// counters they are numbered within, sorted, collapsed into ranges and
597 /// joined.
598 ///
599 /// # Errors
600 ///
601 /// The same as [`format_many`](super::format_many).
602 pub fn default_many(
603 &self,
604 values: &[NumberedValue<'a>],
605 options: &FormatOptions,
606 out: &mut NumberOut<'a>,
607 ) -> Result<(), FormatError> {
608 default_many(values, options, self, out)
609 }
610}
611
612impl fmt::Debug for WriteCx<'_> {
613 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
614 f.debug_struct("WriteCx").field("style", &self.style.name().as_str()).finish_non_exhaustive()
615 }
616}
617
618// --- the default writer -------------------------------------------------------------------
619
620/// The default writer, which writes every counter style that asks for no
621/// other writer: it writes what the counter style's data describes and
622/// nothing else.
623///
624/// One value is written as the word, the opening delimiter, the parts the
625/// value's within-joiner writes, the number and its sub-numbers, and the
626/// closing delimiter. Several values are grouped by the counters they are
627/// numbered within, each group sorted and its consecutive values collapsed
628/// into ranges, and everything joined by the counter style's join texts. A
629/// range never spans two groups; a registered writer may write a range across
630/// a parent.
631#[derive(Debug)]
632pub(super) struct DefaultWriter;
633
634impl CompiledNumberWriter for DefaultWriter {
635 fn write_one<'a>(
636 &self,
637 value: &NumberedValue<'a>,
638 options: &FormatOptions,
639 cx: &WriteCx<'a>,
640 out: &mut NumberOut<'a>,
641 ) -> Result<(), FormatError> {
642 default_one(value, options, cx, out)
643 }
644
645 fn write_many<'a>(
646 &self,
647 values: &[NumberedValue<'a>],
648 options: &FormatOptions,
649 cx: &WriteCx<'a>,
650 out: &mut NumberOut<'a>,
651 ) -> Result<(), FormatError> {
652 default_many(values, options, cx, out)
653 }
654}
655
656/// Returns the default writer, created once and shared by every counter style
657/// that asks for no other writer.
658pub(super) fn default_writer() -> &'static Arc<dyn CompiledNumberWriter> {
659 static WRITER: OnceLock<Arc<dyn CompiledNumberWriter>> = OnceLock::new();
660 WRITER.get_or_init(|| Arc::new(DefaultWriter))
661}