confluent_kafka/admin/options/
create_topics_options.rs1#[derive(Clone, Debug)]
19#[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions")]
20pub struct CreateTopicsOptions {
21 timeout_ms: Option<i32>,
22 validate_only: bool,
23 retry_on_quota_violation: bool,
24}
25
26impl Default for CreateTopicsOptions {
27 fn default() -> Self {
28 Self { timeout_ms: None, validate_only: false, retry_on_quota_violation: true }
29 }
30}
31
32impl CreateTopicsOptions {
33 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#CreateTopicsOptions")]
36 pub fn new() -> Self {
37 Self::default()
38 }
39
40 #[must_use]
51 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#timeoutMs")]
52 pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
53 self.timeout_ms = timeout_ms;
54 self
55 }
56
57 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#timeoutMs")]
60 pub fn timeout_ms(&self) -> Option<i32> {
61 self.timeout_ms
62 }
63
64 #[must_use]
74 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#validateOnly")]
75 pub fn set_validate_only(mut self, validate_only: bool) -> Self {
76 self.validate_only = validate_only;
77 self
78 }
79
80 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#shouldValidateOnly")]
82 pub fn should_validate_only(&self) -> bool {
83 self.validate_only
84 }
85
86 #[must_use]
96 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#retryOnQuotaViolation")]
97 pub fn set_retry_on_quota_violation(mut self, retry_on_quota_violation: bool) -> Self {
98 self.retry_on_quota_violation = retry_on_quota_violation;
99 self
100 }
101
102 #[doc(alias = "org.apache.kafka.clients.admin.CreateTopicsOptions#shouldRetryOnQuotaViolation")]
104 pub fn should_retry_on_quota_violation(&self) -> bool {
105 self.retry_on_quota_violation
106 }
107}
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112
113 #[test]
114 fn defaults_match_java() {
115 let options = CreateTopicsOptions::new();
116 assert_eq!(options.timeout_ms(), None);
117 assert!(!options.should_validate_only());
118 assert!(options.should_retry_on_quota_violation());
119 }
120
121 #[test]
122 fn fluent_setters() {
123 let options = CreateTopicsOptions::new()
124 .set_timeout_ms(Some(5000))
125 .set_validate_only(true)
126 .set_retry_on_quota_violation(false);
127 assert_eq!(options.timeout_ms(), Some(5000));
128 assert!(options.should_validate_only());
129 assert!(!options.should_retry_on_quota_violation());
130 }
131}