Skip to content

Commit 58d16c7

Browse files
authored
Merge pull request #605 from fede1024/davidblewett/struct-setters
Add missing setters for some structs
2 parents e954cf8 + fef0c62 commit 58d16c7

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/message.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,60 @@ impl OwnedMessage {
623623
pub fn detach_headers(&mut self) -> Option<OwnedHeaders> {
624624
self.headers.take()
625625
}
626+
627+
/// Replaces the [`OwnedHeaders`] on this `OwnedMessage`.
628+
pub fn replace_headers(mut self, headers: Option<OwnedHeaders>) -> Self {
629+
if let Some(headers) = headers {
630+
self.headers.replace(headers);
631+
} else {
632+
self.headers = None;
633+
}
634+
self
635+
}
636+
637+
/// Sets the payload for this `OwnedMessage`.
638+
pub fn set_payload(mut self, payload: Option<Vec<u8>>) -> Self {
639+
if let Some(payload) = payload {
640+
self.payload.replace(payload);
641+
} else {
642+
self.payload = None;
643+
}
644+
self
645+
}
646+
647+
/// Sets the key for this `OwnedMessage`.
648+
pub fn set_key(mut self, key: Option<Vec<u8>>) -> Self {
649+
if let Some(key) = key {
650+
self.key.replace(key);
651+
} else {
652+
self.key = None;
653+
}
654+
self
655+
}
656+
657+
/// Sets the topic for this `OwnedMessage`.
658+
pub fn set_topic(mut self, topic: String) -> Self {
659+
self.topic = topic;
660+
self
661+
}
662+
663+
/// Sets the timestamp for this `OwnedMessage`.
664+
pub fn set_timestamp(mut self, timestamp: Timestamp) -> Self {
665+
self.timestamp = timestamp;
666+
self
667+
}
668+
669+
/// Sets the partition for this `OwnedMessage`.
670+
pub fn set_partition(mut self, partition: i32) -> Self {
671+
self.partition = partition;
672+
self
673+
}
674+
675+
/// Sets the offset for this `OwnedMessage`.
676+
pub fn set_offset(mut self, offset: i64) -> Self {
677+
self.offset = offset;
678+
self
679+
}
626680
}
627681

628682
impl Message for OwnedMessage {

src/producer/base_producer.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized, D: IntoOpaque> BaseRecord<'a,
196196
self.headers = Some(headers);
197197
self
198198
}
199+
200+
/// Sets the destination topic of the record.
201+
pub fn topic(mut self, topic: &'a str) -> BaseRecord<'a, K, P, D> {
202+
self.topic = topic;
203+
self
204+
}
205+
206+
/// Sets the delivery opaque of the record.
207+
pub fn delivery_opaque(mut self, delivery_opaque: D) -> BaseRecord<'a, K, P, D> {
208+
self.delivery_opaque = delivery_opaque;
209+
self
210+
}
199211
}
200212

201213
impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized> BaseRecord<'a, K, P, ()> {

0 commit comments

Comments
 (0)