rocketmq_client_rust/consumer/
pull_status.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17use std::fmt::Display;
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
20pub enum PullStatus {
21    /// Founded
22    #[default]
23    Found,
24    /// No new message can be pulled
25    NoNewMsg,
26    /// Filtering results do not match
27    NoMatchedMsg,
28    /// Illegal offset, may be too big or too small
29    OffsetIllegal,
30}
31
32impl From<i32> for PullStatus {
33    fn from(i: i32) -> Self {
34        match i {
35            0 => PullStatus::Found,
36            1 => PullStatus::NoNewMsg,
37            2 => PullStatus::NoMatchedMsg,
38            3 => PullStatus::OffsetIllegal,
39            _ => PullStatus::Found,
40        }
41    }
42}
43
44impl From<PullStatus> for i32 {
45    fn from(p: PullStatus) -> Self {
46        match p {
47            PullStatus::Found => 0,
48            PullStatus::NoNewMsg => 1,
49            PullStatus::NoMatchedMsg => 2,
50            PullStatus::OffsetIllegal => 3,
51        }
52    }
53}
54
55impl Display for PullStatus {
56    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57        match self {
58            PullStatus::Found => write!(f, "FOUND"),
59            PullStatus::NoNewMsg => write!(f, "NO_NEW_MSG"),
60            PullStatus::NoMatchedMsg => write!(f, "NO_MATCHED_MSG"),
61            PullStatus::OffsetIllegal => write!(f, "OFFSET_ILLEGAL"),
62        }
63    }
64}