gen_models/annotations/
progress.rs1use std::io::{self, Write};
4
5use super::AnnotationFileChecksumOverrides;
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum AnnotationFileProgressStage {
10 Sorting,
12 Compressing,
14 BuildingIndex,
16}
17
18pub struct AnnotationFileAddOptions<'a> {
20 pub checksum_overrides: AnnotationFileChecksumOverrides,
22 pub progress: Option<&'a mut dyn FnMut(AnnotationFileProgressStage)>,
24}
25
26pub(super) fn report_annotation_file_progress(
27 progress: &mut Option<&mut dyn FnMut(AnnotationFileProgressStage)>,
28 stage: AnnotationFileProgressStage,
29) {
30 if let Some(callback) = progress.as_mut() {
31 callback(stage);
32 }
33}
34
35pub(super) struct ReportCompressionOnFirstWrite<W, F> {
37 writer: W,
38 on_first_write: Option<F>,
39}
40
41impl<W, F> ReportCompressionOnFirstWrite<W, F> {
42 pub(super) fn new(writer: W, on_first_write: F) -> Self {
43 Self {
44 writer,
45 on_first_write: Some(on_first_write),
46 }
47 }
48}
49
50impl<W: Write, F: FnMut()> Write for ReportCompressionOnFirstWrite<W, F> {
51 fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
52 if !buffer.is_empty()
53 && let Some(mut on_first_write) = self.on_first_write.take()
54 {
55 on_first_write();
56 }
57
58 self.writer.write(buffer)
59 }
60
61 fn flush(&mut self) -> io::Result<()> {
62 self.writer.flush()
63 }
64}