forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamemode.rs
More file actions
28 lines (26 loc) · 676 Bytes
/
Copy pathgamemode.rs
File metadata and controls
28 lines (26 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use num_derive::{FromPrimitive, ToPrimitive};
use serde::{Deserialize, Serialize};
/// A gamemode.
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, FromPrimitive, ToPrimitive,
)]
#[serde(rename_all = "snake_case")]
#[repr(u8)]
pub enum Gamemode {
Survival = 0,
Creative = 1,
Adventure = 2,
Spectator = 3,
}
impl Gamemode {
/// Gets a gamemode from its ID.
pub fn from_id(id: u8) -> Option<Self> {
Some(match id {
0 => Gamemode::Survival,
1 => Gamemode::Creative,
2 => Gamemode::Adventure,
3 => Gamemode::Spectator,
_ => return None,
})
}
}