This Rust project demonstrates the use of the serde
crate to serialize and deserialize state data to and from YAML files. The project features a simple state management system where the state can be saved, loaded, and modified through basic commands.
- State Management: Track the position and health of an entity.
- Serialization: Save the current state to a YAML file.
- Deserialization: Load a previously saved state from a YAML file.
- Interactive Commands: Move the entity, adjust health, and save or quit the application through user input.
- main.rs: The entry point of the application. Manages the main loop, user input, and state updates.
- state.rs: Defines the
State
andPoint
structures, along with methods to manipulate and serialize/deserialize them. - actions.rs: Handles user input and defines the various actions that can be performed (e.g., move left, right, heal, etc.).
-
Clone the Repository:
git clone --depth=1 https://github.com/Davenchy/serde_yaml_demo.git cd serde_yaml_demo
-
Run the Application:
cargo run
-
Available Commands:
Left
orl
: Move the entity 5 units to the left.Right
orr
: Move the entity 5 units to the right.Up
oru
: Move the entity 5 units up.Down
ord
: Move the entity 5 units down.Damage
ora
: Reduce the entity’s health by 10.Heal
orh
: Increase the entity’s health by 10.Save
ors
: Save the current state tostate.yml
.Quit
orq
: Exit the application.
-
YAML State File:
- The state is saved to
state.yml
in the project’s root directory. - On application start, if
state.yml
exists, the state will be loaded from it; otherwise, a new state will be created on theSave
action.
- The state is saved to
- serde for serialization and deserialization.
- serde_yaml_ng for working with YAML files.
This project was created as a learning exercise to explore Rust’s serialization capabilities with serde
. It is archived and not under active development.
This project is licensed under the MIT License.