rocketmq_client_rust/producer/
send_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;
18
19use serde::Deserialize;
20use serde::Deserializer;
21use serde::Serialize;
22use serde::Serializer;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
25pub enum SendStatus {
26    #[default]
27    SendOk,
28    FlushDiskTimeout,
29    FlushSlaveTimeout,
30    SlaveNotAvailable,
31}
32
33impl Serialize for SendStatus {
34    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
35    where
36        S: Serializer,
37    {
38        let value = match self {
39            SendStatus::SendOk => "SEND_OK",
40            SendStatus::FlushDiskTimeout => "FLUSH_DISK_TIMEOUT",
41            SendStatus::FlushSlaveTimeout => "FLUSH_SLAVE_TIMEOUT",
42            SendStatus::SlaveNotAvailable => "SLAVE_NOT_AVAILABLE",
43        };
44        serializer.serialize_str(value)
45    }
46}
47
48impl<'de> Deserialize<'de> for SendStatus {
49    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
50    where
51        D: Deserializer<'de>,
52    {
53        struct StoreTypeVisitor;
54
55        impl serde::de::Visitor<'_> for StoreTypeVisitor {
56            type Value = SendStatus;
57
58            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
59                formatter.write_str("a string representing SendStatus")
60            }
61
62            fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
63            where
64                E: serde::de::Error,
65            {
66                match value {
67                    "SEND_OK" => Ok(SendStatus::SendOk),
68                    "FLUSH_DISK_TIMEOUT" => Ok(SendStatus::FlushDiskTimeout),
69                    "FLUSH_SLAVE_TIMEOUT" => Ok(SendStatus::FlushSlaveTimeout),
70                    "SLAVE_NOT_AVAILABLE" => Ok(SendStatus::SlaveNotAvailable),
71                    _ => Err(serde::de::Error::unknown_variant(
72                        value,
73                        &[
74                            "SEND_OK",
75                            "FLUSH_DISK_TIMEOUT",
76                            "FLUSH_SLAVE_TIMEOUT",
77                            "SLAVE_NOT_AVAILABLE",
78                        ],
79                    )),
80                }
81            }
82        }
83        deserializer.deserialize_str(StoreTypeVisitor)
84    }
85}