Fallibe default? #373
-
|
I have this setup: #[derive(Builder)]
pub struct SpecificSingleObjectWriter<T>
where
T: AvroSchema,
{
// TODO: Make default fallibe
#[builder(
with = |schema: Schema| -> Result<_, Error> { ResolvedOwnedSchema::new(schema) },
default = ResolvedOwnedSchema::new(T::get_schema()).expect("Invalid schema")
)]
resolved: ResolvedOwnedSchema,
#[builder(
default = RabinFingerprintHeader::from_schema(resolved.get_root_schema()).build_header(),
with = |header_builder: impl HeaderBuilder| header_builder.build_header(),
)]
header: Vec<u8>,
/// Should data be encoded as human-readable where possible.
human_readable: bool,
/// How many bytes should blocks of array and map values be.
///
/// Every block except the last will have at least this size.
map_array_target_block_size: Option<usize>,
#[builder(skip)]
_model: PhantomData<T>,
}The |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi! That's a good question. Doing this type of thing is definitely what a fallback to So if it's a really rare occurrence, I'd recommend just going for a |
Beta Was this translation helpful? Give feedback.
Hi! That's a good question. Doing this type of thing is definitely what a fallback to
new-function-based builder is for, and I can't find an easier way to do that with the current set of attributes API provided inbon. I understand the inconvenience of having to switch to that, but I also want to keep the attributes API as small and simple as possible. Ideally, an attribute should exist only if there is no other way to achieve the same using existing APIs, or if the desired behaviour emerges far too often, which would justify having a shorthand attribute syntax for it.So if it's a really rare occurrence, I'd recommend just going for a
new-function-based builder