Skip to main content

rocketmq_client_rust/consumer/
pull_status.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::Display;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
18pub enum PullStatus {
19    /// Founded
20    #[default]
21    Found,
22    /// No new message can be pulled
23    NoNewMsg,
24    /// Filtering results do not match
25    NoMatchedMsg,
26    /// Illegal offset, may be too big or too small
27    OffsetIllegal,
28}
29
30impl From<i32> for PullStatus {
31    fn from(i: i32) -> Self {
32        match i {
33            0 => PullStatus::Found,
34            1 => PullStatus::NoNewMsg,
35            2 => PullStatus::NoMatchedMsg,
36            3 => PullStatus::OffsetIllegal,
37            _ => PullStatus::Found,
38        }
39    }
40}
41
42impl From<PullStatus> for i32 {
43    fn from(p: PullStatus) -> Self {
44        match p {
45            PullStatus::Found => 0,
46            PullStatus::NoNewMsg => 1,
47            PullStatus::NoMatchedMsg => 2,
48            PullStatus::OffsetIllegal => 3,
49        }
50    }
51}
52
53impl Display for PullStatus {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        match self {
56            PullStatus::Found => write!(f, "FOUND"),
57            PullStatus::NoNewMsg => write!(f, "NO_NEW_MSG"),
58            PullStatus::NoMatchedMsg => write!(f, "NO_MATCHED_MSG"),
59            PullStatus::OffsetIllegal => write!(f, "OFFSET_ILLEGAL"),
60        }
61    }
62}