Can anyone have a quick look at my architecture + use of `std::mem::replace`?
⚓ Rust 📅 2026-05-22 👤 surdeus 👁️ 2So I've been trying to learn rust by creating a TUI application to keep track of all my coding projects using ratatui. https://github.com/fgassmann/projektor (No vibecoding btw.)
However there are some things I'm not sure if I'm doing the right way, so I would appreciate some feedback before I continue.
One thing is I'm currently using this enum to keep track of the ui state (e.g. you start in Projectview, press n and then it changes to CreatingProject).
I was fairly happy with this until I introduced the Error state which basically just wraps the state the error occured in and displays it as a kind of
popup until the user acknowledges it.
However since then i've been having to use std::mem::replace a bunch of times to convert back from Error to the previous state.
(also I'm not sure how well this will work once I build the other tabs?)
#[derive(Debug)]
pub enum AppMode {
ProjectView,
EditingProject(editor::ProjectEditor),
CreatingProject(editor::ProjectEditor),
Error(String, Box<AppMode>),
}
let mode = std::mem::replace(&mut self.mode, AppMode::ProjectView);
match mode {
AppMode::EditingProject(p) => {
// do something
}
}
I also feel like I have a wierd mix between the Elm architecture and Component architecture?
But that might just be because I'm using components like ratatui-textarea?
So any feedback on architecture/ structure of the project is also appreciated.
Also I know I still have some bad error handling,
unused import and missing features (currently the config doesn't get red from a file but is hardcoded for testing).
So please don't mind those.
6 posts - 4 participants
🏷️ Rust_feed