git_bug/entities/issue/data/
status.rs1use std::{fmt::Display, str::FromStr};
13
14use serde::{Deserialize, Serialize};
15
16#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize, Serialize)]
17pub enum Status {
19 Open,
21
22 Closed,
24}
25
26impl FromStr for Status {
27 type Err = decode::Error;
28
29 fn from_str(value: &str) -> Result<Self, Self::Err> {
30 let value = match value {
31 "open" => Self::Open,
32 "closed" => Self::Closed,
33 other => return Err(decode::Error::UnknownStatusString(other.to_owned())),
34 };
35 Ok(value)
36 }
37}
38impl TryFrom<u64> for Status {
39 type Error = decode::Error;
40
41 fn try_from(value: u64) -> Result<Self, Self::Error> {
42 let value = match value {
43 1 => Self::Open,
44 2 => Self::Closed,
45 other => return Err(decode::Error::UnknownStatus(other)),
46 };
47 Ok(value)
48 }
49}
50
51impl From<Status> for u64 {
52 fn from(value: Status) -> Self {
53 match value {
54 Status::Open => 1,
55 Status::Closed => 2,
56 }
57 }
58}
59impl Display for Status {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 match self {
62 Status::Open => f.write_str("open"),
63 Status::Closed => f.write_str("closed"),
64 }
65 }
66}
67
68#[allow(missing_docs)]
69pub mod decode {
70 #[derive(Debug, thiserror::Error)]
71 pub enum Error {
72 #[error("The status with id ({0}) is not known.")]
73 UnknownStatus(u64),
74
75 #[error("The status named ({0}) is not known.")]
76 UnknownStatusString(String),
77 }
78}