ariadne icon indicating copy to clipboard operation
ariadne copied to clipboard

Remove redundant setters in the report builder.

Open Aurora2500 opened this issue 3 years ago • 2 comments
trafficstars

The ReportBuilder type has a bunch of duplicate setter functions that call their counterpart (set_message and with_message, set_note and with_note, etc).

It might be a good idea to remove these redundant setters as they needlessly complicate the interface of this type.

Aurora2500 avatar May 25 '22 21:05 Aurora2500

Hm... in general I understand why both versions exist, but on the other hand, I also agree that most people are probably using only one "creating-version" for the builder and I'd even say, that most people would use the building-pattern (I don't know the name of it) but I mean this one:

Report::build(...)
     .with_message(...)
     .with_note(...)
     // and so on

TornaxO7 avatar Jun 13 '22 14:06 TornaxO7

I disagree that the functions are redundant. Creating a report inline and modifying an existing report are two conceptually distinct operations.

zesterer avatar Jul 04 '22 20:07 zesterer

set_xxx() methods are quite useful for inline mutation of the builder, particularly within loops(including fold iterator).

let mut report_builder = Report::build(...);

for my_error in errors {
	report_builder.add_label(Label::new(...));
}

report_builder.finish();

abiriadev avatar Sep 21 '23 05:09 abiriadev

Yep, they're two different use-cases. I'll close this now.

zesterer avatar Sep 21 '23 14:09 zesterer