Skip to main content

rocketmq_client_rust/consumer/
notify_result.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
18pub struct NotifyResult {
19    has_msg: bool,
20    polling_full: bool,
21}
22
23impl NotifyResult {
24    pub fn new(has_msg: bool, polling_full: bool) -> Self {
25        Self { has_msg, polling_full }
26    }
27
28    #[inline]
29    pub fn has_msg(&self) -> bool {
30        self.has_msg
31    }
32
33    #[inline]
34    pub fn is_has_msg(&self) -> bool {
35        self.has_msg
36    }
37
38    #[inline]
39    pub fn set_has_msg(&mut self, has_msg: bool) {
40        self.has_msg = has_msg;
41    }
42
43    #[inline]
44    pub fn polling_full(&self) -> bool {
45        self.polling_full
46    }
47
48    #[inline]
49    pub fn is_polling_full(&self) -> bool {
50        self.polling_full
51    }
52
53    #[inline]
54    pub fn set_polling_full(&mut self, polling_full: bool) {
55        self.polling_full = polling_full;
56    }
57}
58
59impl fmt::Display for NotifyResult {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        write!(
62            f,
63            "NotifyResult{{hasMsg={}, pollingFull={}}}",
64            self.has_msg, self.polling_full
65        )
66    }
67}
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn notify_result_getters_setters_match_java_shape() {
75        let mut result = NotifyResult::default();
76        assert!(!result.is_has_msg());
77        assert!(!result.is_polling_full());
78
79        result.set_has_msg(true);
80        result.set_polling_full(true);
81
82        assert!(result.has_msg());
83        assert!(result.polling_full());
84        assert_eq!(result.to_string(), "NotifyResult{hasMsg=true, pollingFull=true}");
85    }
86}