pub trait DiffFlavor {
Show 20 methods
// Required methods
fn format_value(&self, peek: Peek<'_, '_>, w: &mut dyn Write) -> Result;
fn field_presentation(&self, field: &Field) -> FieldPresentation;
fn struct_open(&self, name: &str) -> Cow<'static, str>;
fn struct_close(&self, name: &str, self_closing: bool) -> Cow<'static, str>;
fn field_separator(&self) -> &'static str;
fn seq_open(&self) -> Cow<'static, str>;
fn seq_close(&self) -> Cow<'static, str>;
fn item_separator(&self) -> &'static str;
fn comment(&self, text: &str) -> String;
fn format_field(&self, name: &str, value: &str) -> String;
fn format_field_prefix(&self, name: &str) -> String;
fn format_field_suffix(&self) -> &'static str;
// Provided methods
fn trailing_separator(&self) -> &'static str { ... }
fn format_seq_item<'a>(
&self,
_item_type: &str,
value: &'a str,
) -> Cow<'a, str> { ... }
fn format_seq_field_open(&self, field_name: &str) -> String { ... }
fn format_seq_field_close(&self, _field_name: &str) -> Cow<'static, str> { ... }
fn struct_open_close(&self) -> &'static str { ... }
fn type_comment(&self, _name: &str) -> Option<String> { ... }
fn format_child_open(&self, name: &str) -> Cow<'static, str> { ... }
fn format_child_close(&self, _name: &str) -> Cow<'static, str> { ... }
}Expand description
A diff output flavor that knows how to format values and present fields.
Required Methods§
Sourcefn format_value(&self, peek: Peek<'_, '_>, w: &mut dyn Write) -> Result
fn format_value(&self, peek: Peek<'_, '_>, w: &mut dyn Write) -> Result
Format a scalar/leaf value into a writer.
The output should NOT include surrounding quotes for strings - the renderer will add appropriate syntax based on context.
Sourcefn field_presentation(&self, field: &Field) -> FieldPresentation
fn field_presentation(&self, field: &Field) -> FieldPresentation
Determine how a field should be presented.
Sourcefn struct_open(&self, name: &str) -> Cow<'static, str>
fn struct_open(&self, name: &str) -> Cow<'static, str>
Opening syntax for a struct/object.
- Rust:
Point { - JSON:
{ - XML:
<Point
Sourcefn struct_close(&self, name: &str, self_closing: bool) -> Cow<'static, str>
fn struct_close(&self, name: &str, self_closing: bool) -> Cow<'static, str>
Closing syntax for a struct/object.
- Rust:
} - JSON:
} - XML:
/>(self-closing) or</Point>
Sourcefn field_separator(&self) -> &'static str
fn field_separator(&self) -> &'static str
Separator between fields.
- Rust:
, - JSON:
, - XML:
(space between attributes)
Sourcefn seq_open(&self) -> Cow<'static, str>
fn seq_open(&self) -> Cow<'static, str>
Opening syntax for a sequence/array.
- Rust:
[ - JSON:
[ - XML: (wrapper element, handled differently)
Sourcefn seq_close(&self) -> Cow<'static, str>
fn seq_close(&self) -> Cow<'static, str>
Closing syntax for a sequence/array.
- Rust:
] - JSON:
] - XML: (wrapper element, handled differently)
Sourcefn item_separator(&self) -> &'static str
fn item_separator(&self) -> &'static str
Separator between sequence items.
- Rust:
, - JSON:
, - XML: (newlines/whitespace)
Sourcefn comment(&self, text: &str) -> String
fn comment(&self, text: &str) -> String
Format a comment (for collapsed items).
- Rust:
/* ...5 more */ - JSON:
// ...5 more - XML:
<!-- ...5 more -->
Sourcefn format_field(&self, name: &str, value: &str) -> String
fn format_field(&self, name: &str, value: &str) -> String
Format a field assignment (name and value).
- Rust:
name: value - JSON:
"name": value - XML:
name="value"
Sourcefn format_field_prefix(&self, name: &str) -> String
fn format_field_prefix(&self, name: &str) -> String
Format just the field name with assignment operator.
- Rust:
name: - JSON:
"name": - XML:
name="
Sourcefn format_field_suffix(&self) -> &'static str
fn format_field_suffix(&self) -> &'static str
Suffix after the value (if any).
- Rust: `` (empty)
- JSON: `` (empty)
- XML:
"(closing quote)
Provided Methods§
Sourcefn trailing_separator(&self) -> &'static str
fn trailing_separator(&self) -> &'static str
Trailing comma/separator (no trailing space). Used at end of lines when fields are broken across lines.
- Rust:
, - JSON:
, - XML: `` (empty - no trailing separator)
Sourcefn format_seq_item<'a>(&self, _item_type: &str, value: &'a str) -> Cow<'a, str>
fn format_seq_item<'a>(&self, _item_type: &str, value: &'a str) -> Cow<'a, str>
Format a sequence item value, optionally wrapping in element tags.
- Rust:
0(no wrapping) - JSON:
0(no wrapping) - XML:
<i32>0</i32>(wrapped in element)
Sourcefn format_seq_field_open(&self, field_name: &str) -> String
fn format_seq_field_open(&self, field_name: &str) -> String
Opening for a sequence that is a struct field value.
- Rust:
fieldname: [ - JSON:
"fieldname": [ - XML:
<fieldname>(wrapper element, not attribute!)
Sourcefn format_seq_field_close(&self, _field_name: &str) -> Cow<'static, str>
fn format_seq_field_close(&self, _field_name: &str) -> Cow<'static, str>
Closing for a sequence that is a struct field value.
- Rust:
] - JSON:
] - XML:
</fieldname>
Sourcefn struct_open_close(&self) -> &'static str
fn struct_open_close(&self) -> &'static str
Close the opening tag when there are children.
- Rust: `` (empty - no separate closing for opening tag)
- JSON: `` (empty)
- XML:
>(close the opening tag before children)
Sourcefn type_comment(&self, _name: &str) -> Option<String>
fn type_comment(&self, _name: &str) -> Option<String>
Optional type name comment to show after struct_open. Rendered in muted color for readability.
- Rust: None (type name is in struct_open)
- JSON: Some(“/* Point */”)
- XML: None
Sourcefn format_child_open(&self, name: &str) -> Cow<'static, str>
fn format_child_open(&self, name: &str) -> Cow<'static, str>
Opening wrapper for a child element (nested struct field).
- Rust:
field_name:(field prefix) - JSON:
"field_name":(field prefix) - XML: `` (empty - no wrapper, or could be
<field_name>\n)
Sourcefn format_child_close(&self, _name: &str) -> Cow<'static, str>
fn format_child_close(&self, _name: &str) -> Cow<'static, str>
Closing wrapper for a child element (nested struct field).
- Rust: `` (empty)
- JSON: `` (empty)
- XML: `` (empty, or
</field_name>if wrapping)