use quote::quote;
use super::{DisplayOptions, DisplayOutput, Segment, SegmentKind, access};
pub struct KeyValueStyleSyntax {
pub pretty: bool,
}
impl KeyValueStyleSyntax {
pub fn render(&self, opts: &DisplayOptions) -> syn::Result<DisplayOutput> {
let mut out = DisplayOutput::new();
let sep = if self.pretty { "\n" } else { " " };
for (i, f) in opts.fields.iter().enumerate() {
let a = access(f, opts.use_self);
out.push(Segment::literal(SegmentKind::FieldName, &f.display_name()?));
out.push(Segment::literal(SegmentKind::Assign, "="));
out.push(Segment::placeholder(SegmentKind::Value, quote! { #a }));
if i + 1 < opts.fields.len() {
out.push(Segment::literal(SegmentKind::Separator, sep));
}
}
Ok(out)
}
}