pub struct ProducerRecordOptionsBuilder<K, V> { /* private fields */ }Expand description
Fluent builder for ProducerRecordOptions.
Self::new takes no parameters, every parameter has a fluent setter, and
Self::build validates the mandatory ones — returning
Error::LocalIllegalArgument if they were not set. Like
ProducerRecordOptions it has no Java counterpart.
Implementations§
Source§impl<K, V> ProducerRecordOptionsBuilder<K, V>
impl<K, V> ProducerRecordOptionsBuilder<K, V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a builder with every mandatory parameter unset and every other parameter at the value Java passes on the caller’s behalf.
Sourcepub fn set_topic(self, topic: String) -> Self
pub fn set_topic(self, topic: String) -> Self
Sets ProducerRecordOptions::topic, a mandatory parameter: Self::build
returns an error if it was not set.
§Arguments
topic- the topic the record will be appended to
§Returns
This builder.
Sourcepub fn set_partition(self, partition: Option<i32>) -> Self
pub fn set_partition(self, partition: Option<i32>) -> Self
Sourcepub fn set_timestamp(self, timestamp: Option<i64>) -> Self
pub fn set_timestamp(self, timestamp: Option<i64>) -> Self
Sourcepub fn set_value(self, value: Option<V>) -> Self
pub fn set_value(self, value: Option<V>) -> Self
Sets ProducerRecordOptions::value, a mandatory parameter: Self::build
returns an error if it was not set.
§Arguments
value- the record contents
§Returns
This builder.
Sourcepub fn set_headers(self, headers: Option<RecordHeaders>) -> Self
pub fn set_headers(self, headers: Option<RecordHeaders>) -> Self
Sourcepub fn build(self) -> Result<ProducerRecordOptions<K, V>, Error>
pub fn build(self) -> Result<ProducerRecordOptions<K, V>, Error>
Returns the built options.
The mandatory parameters are validated here rather than
being named in the constructor, so a later Java version that makes one of
them optional changes the set this accepts instead of adding a second
constructor. Today there is one mandatory set: topic, value.
§Errors
Error::is_local_illegal_argument_error, naming the first parameter of that set which was not given a setter call. Only presence is checked here; semantic validation belongs to the method the options are passed to.