Skip to content

Instantly share code, notes, and snippets.

@Kielan
Created August 14, 2025 18:17
Show Gist options
  • Save Kielan/1366476fb6c0c28492e56edfa4024d6c to your computer and use it in GitHub Desktop.
Save Kielan/1366476fb6c0c28492e56edfa4024d6c to your computer and use it in GitHub Desktop.
Example Impl of FF7/BOTW Inventory in Rust
#[derive(Debug)]
struct Player {
state: State,
}
impl Player {
fn new() -> Self {
Self { state: PlayerCharacterInstance }
}
fn collect(&mut self, ability: Transition) {
match (&self.state, power) {
(&self.state, ItemPickup) => self.state = PlayerCharacterInstanceNewStateItemPickup(ItemPickup),
(_, ItemPickupAntipattern) => self.state = PlayerCharacterInstanceNewStateItemPickupAntipattern(ItemPickupAntipattern),
(_, ItemPickupTest) => {
printl!("item picked up")
}
}
}
}
fn main() {
let mut player_instance = Player::new();
player_instance.collect(ItemPickup);
player_instance.collect(ItemPickupAntipattern);
player_instance.collect(ItemPickupTest);
assert!(player_instance.state == PlayerCharacterInstanceStateItemPickup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment