1#[derive(Clone, Debug, Default, Eq, PartialEq)]
2pub enum AuthStatus<User> {
3 #[default]
4 Loading,
5 Authenticated(User),
6 Unauthenticated,
7}
8
9impl<User> AuthStatus<User> {
10 pub fn is_loading(&self) -> bool {
11 matches!(self, Self::Loading)
12 }
13
14 pub fn is_authenticated(&self) -> bool {
15 matches!(self, Self::Authenticated(_))
16 }
17
18 pub fn is_unauthenticated(&self) -> bool {
19 matches!(self, Self::Unauthenticated)
20 }
21
22 pub fn user(&self) -> Option<&User> {
23 match self {
24 Self::Authenticated(user) => Some(user),
25 Self::Loading | Self::Unauthenticated => None,
26 }
27 }
28
29 pub fn into_user(self) -> Option<User> {
30 match self {
31 Self::Authenticated(user) => Some(user),
32 Self::Loading | Self::Unauthenticated => None,
33 }
34 }
35}