Skip to content

Commit

Permalink
Add Dawntrail to Expansion enum (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
endervad authored Jul 26, 2024
1 parent 3b53e11 commit 45fe9da
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/tomestone-sqpack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ pub enum Expansion {
Ex2 = 2,
Ex3 = 3,
Ex4 = 4,
Ex5 = 5,
}

impl Expansion {
Expand All @@ -476,6 +477,7 @@ impl Expansion {
"ex2" => Ok(Expansion::Ex2),
"ex3" => Ok(Expansion::Ex3),
"ex4" => Ok(Expansion::Ex4),
"ex5" => Ok(Expansion::Ex5),
_ => Err(EnumParseError),
}
}
Expand All @@ -487,17 +489,19 @@ impl Expansion {
2 => Ok(Expansion::Ex2),
3 => Ok(Expansion::Ex3),
4 => Ok(Expansion::Ex4),
5 => Ok(Expansion::Ex5),
_ => Err(EnumParseError),
}
}

pub fn iter_all() -> impl Iterator<Item = &'static Expansion> {
const LIST: [Expansion; 5] = [
const LIST: [Expansion; 6] = [
Expansion::Base,
Expansion::Ex1,
Expansion::Ex2,
Expansion::Ex3,
Expansion::Ex4,
Expansion::Ex5,
];
LIST.iter()
}
Expand All @@ -509,6 +513,7 @@ impl Expansion {
Expansion::Ex2 => "ex2",
Expansion::Ex3 => "ex3",
Expansion::Ex4 => "ex4",
Expansion::Ex5 => "ex5",
}
}
}
Expand Down Expand Up @@ -1078,6 +1083,10 @@ mod tests {
Expansion::parse_name(Expansion::Ex4.name()).unwrap(),
Expansion::Ex4
);
assert_eq!(
Expansion::parse_name(Expansion::Ex5.name()).unwrap(),
Expansion::Ex5
);

assert_eq!(Expansion::from_u8(0).unwrap() as u8, 0);
assert_eq!(Expansion::from_u8(1).unwrap() as u8, 1);
Expand All @@ -1104,6 +1113,10 @@ mod tests {
Expansion::from_u8(Expansion::Ex4 as u8).unwrap(),
Expansion::Ex4
);
assert_eq!(
Expansion::from_u8(Expansion::Ex5 as u8).unwrap(),
Expansion::Ex5
);
}

#[derive(Clone)]
Expand Down

0 comments on commit 45fe9da

Please sign in to comment.