1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{Result, Rudof, api::pgschema::PgSchemaOperations, formats::ResultPgSchemaValidationFormat};
use std::io;
/// Builder for the `serialize_pgschema_validation_results` operation.
pub struct SerializePgSchemaValidationResultsBuilder<'a, W: io::Write> {
rudof: &'a Rudof,
writer: &'a mut W,
show_colors: Option<bool>,
result_pg_schema_validation_format: Option<&'a ResultPgSchemaValidationFormat>,
}
impl<'a, W: io::Write> SerializePgSchemaValidationResultsBuilder<'a, W> {
/// Create a new serialization builder.
///
/// Internal: created by `Rudof::serialize_pgschema_validation_results()`.
pub(crate) fn new(rudof: &'a Rudof, writer: &'a mut W) -> Self {
Self {
rudof,
writer,
result_pg_schema_validation_format: None,
show_colors: None,
}
}
/// Set the output format to use when serializing validation results.
///
/// # Arguments
///
/// * `result_pg_schema_validation_format` - Desired result format (e.g. one of the supported
/// `ResultPgSchemaValidationFormat` variants)
pub fn with_result_pg_schema_validation_format(
mut self,
result_pg_schema_validation_format: &'a ResultPgSchemaValidationFormat,
) -> Self {
self.result_pg_schema_validation_format = Some(result_pg_schema_validation_format);
self
}
/// Set whether to include ANSI color codes in the output (if supported by the chosen format).
///
/// # Arguments
///
/// * `show_colors` - If true, include ANSI color codes in the output (defaults to true if None)
pub fn with_show_colors(mut self, show_colors: bool) -> Self {
self.show_colors = Some(show_colors);
self
}
/// Execute the serialization with the configured parameters.
pub fn execute(self) -> Result<()> {
<Rudof as PgSchemaOperations>::serialize_pgschema_validation_results(
self.rudof,
self.result_pg_schema_validation_format,
self.show_colors,
self.writer,
)
}
}