mit_commit_message_lints/mit/lib/
author_state.rs1use time::OffsetDateTime;
2
3#[derive(Debug, Eq, PartialEq)]
5pub enum AuthorState<T> {
6 Some(T),
8
9 Timeout(OffsetDateTime),
11
12 None,
14}
15
16impl<T> AuthorState<T> {
17 pub const fn is_none(&self) -> bool {
19 matches!(self, Self::None)
20 }
21
22 pub const fn is_timeout(&self) -> bool {
24 matches!(self, Self::Timeout(_))
25 }
26
27 pub const fn is_some(&self) -> bool {
29 matches!(self, Self::Some(_))
30 }
31
32 pub fn unwrap(self) -> T {
38 match self {
39 Self::Some(value) => value,
40 Self::None => panic!("called `AuthorState::unwrap()` on a `None` value"),
41 Self::Timeout(value) => panic!(
42 "called `AuthorState::unwrap()` on a `Timeout({})` value",
43 value
44 ),
45 }
46 }
47}
48
49impl<T> From<AuthorState<T>> for Option<T> {
50 fn from(values: AuthorState<T>) -> Self {
51 match values {
52 AuthorState::Some(inner) => Some(inner),
53 AuthorState::Timeout(_) | AuthorState::None => None,
54 }
55 }
56}