Closed casey closed 3 years ago
@casey This is a limitation of derive_builder.
All structs in rss
crate with builders have Default
trait implemented. This means that builder's .build()
always returns Ok()
. So, it is safe to call .build().unwrap()
.
This is ugly, so you can prefer to stop using builders and use regular setters.
e. g. instead of
let channel = ChannelBuilder::default()
.title("title")
.build()
.unwrap();
just write
let mut channel = Channel::default();
channel.set_title("title");
or (if you need it in an expression)
let channel = {
let mut channel = Channel::default();
channel.set_title("title");
channel
};
Next version will have all fields public, so it will be possible to write like this:
let channel = Channel {
title: "title",
..Default::default(),
};
I'm using the library to generate a feed for my personal blog, and I have an error type with a lot of
From<lib::Error> for MyError
implementations for converting errors from crates I use to my general error type.ChannelBuilder::build returns
String
as the error type, so in order to get nice error conversions with the?
operator, I would have to implementFrom<String> for MyError
, which seems error (haha) prone.It would be nice if
ChannelBuilder::build
returned a type specific to therss
crate, likerss::BuildError
, which could even be a simple wrapper for the error message, i.e.struct BuildError(String)
.Also, thanks so much for this library!