I’m excited to share this as my first post on the DEV Community! 🎉
💡 Want to build your first GUI app in Rust?
This post walks you through creating a Student Analyzer app using egui
, with form inputs, grade logic, and CSV export — all in a beautiful GUI using the eframe
crate!
🎯 What You’ll Build
A minimal yet functional GUI that:
✅ Accepts student details and marks
✅ Calculates average and pass/fail result
✅ Exports the data into a CSV file
🧱 App Structure
We build this using the eframe
framework — a native GUI library powered by egui
.
Main building blocks:
-
StudentApp
struct – Core data model of GUI application -
impl Default
– Initial state of app at launch -
impl eframe::App
– Draws UI and handles logic
🧠 Code Breakdown – GUI + Logic
This code defines the app’s data model and initial state.
struct StudentApp{
name: String,
roll_no: String,
subjects: Vec<String>,
selected_subjects: [usize; 7],
marks: [String; 7],
average: Option<f32>,
result: Option<String>,
}
impl Default for StudentApp {
fn default() -> Self {
Self {
name: String::new(),
roll_no: String::new(),
subjects: vec![
"Math".to_string(),
"Science".to_string(),
"English".to_string(),
"Social".to_string(),
"Computer".to_string(),
"Hindi".to_string(),
"Tamil".to_string(),
],
selected_subjects: [0; 7],
marks: Default::default(),
average: None,
result: None,
}
}
}
And
In impl eframe::App, the update()
function gets called repeatedly while your app is running.
Inside this function, we:
- Create a window (CentralPanel) where the UI lives.
- Add form fields for user input (like name, roll number, subjects, marks).
- Handle logic for computing average and result.
- Render the result to the user.
🔖 Code Purpose Table (Highlight View)
Purpose | Explanation |
---|---|
TextEdit::singleline(...) |
Draws input box for user text |
ui.button("Add Marks") |
Adds current mark to the list |
calculate_result() |
Computes average and pass/fail |
write_to_csv() |
Appends form data to a CSV file |
egui::CentralPanel::default().show(...) |
Main layout container of the UI with title centered |
egui::ComboBox::from_id_source(...) |
Renders subject dropdown for each entry |
📤 CSV Export Logic
This snippet writes the data by saving each student's entry into a CSV file for future use or reporting.
let file_path = "student_analyzer.csv";
let file_exists = std::path::Path::new(file_path).exists();
let file = OpenOptions::new()
.create(true)
.append(true)
.open(file_path)
.expect("Cannot open file");
✨ Preview Screens
💻 Input Form
The StudentApp screen at launch, with fields for name, subject, and marks.
📊 Average + Result View
The user adds multiple marks, and the app calculates the average and displays the result.
📁 CSV Export Confirmation
A student_analyzer.csv
file stores the entered data persistently for later use.
📎 Try the Full App
👉 Full post with detailed explanations and setup steps:
🔗 Techn0tz Full Blog
Source code
👉 Download the Student Analyzer Rust code
💭 What’s Next?
In the next post, test your Rust foundations with a quick interactive Mini Quiz on Techn0tz!
Thanks for reading! 🌱
This is my first post on DEV, and I'm truly excited to be part of this amazing community. If you found it helpful or have suggestions, feel free to drop a comment or connect! 🚀-Techn0tz