-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_id.rs
More file actions
37 lines (28 loc) · 870 Bytes
/
form_id.rs
File metadata and controls
37 lines (28 loc) · 870 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
29
30
31
32
33
34
35
36
37
use std::{fmt::Display, str::FromStr};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use crate::load_order::LoadOrder;
#[derive(
Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, DeserializeFromStr, SerializeDisplay,
)]
pub struct GlobalFormId(u32);
impl GlobalFormId {
pub fn new(form_id: u32) -> Self {
GlobalFormId(form_id)
}
}
impl Display for GlobalFormId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:08x}", self.0)
}
}
impl FromStr for GlobalFormId {
type Err = String;
/// Parse a value like `043F0001`
fn from_str(s: &str) -> Result<Self, Self::Err> {
let form_id = u32::from_str_radix(s, 16).map_err(|err| err.to_string())?;
Ok(Self(form_id))
}
}
pub trait FormIdContainer {
fn get_global_form_id(&self) -> GlobalFormId;
}