DEV Community

Cover image for Build a RUST GUI App: Student Analyzer + CSV Export (using egui)
manjushaps
manjushaps

Posted on • Originally published at manjushaps.github.io

Build a RUST GUI App: Student Analyzer + CSV Export (using egui)

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

Egui Window Preview


🧱 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,
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

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");
Enter fullscreen mode Exit fullscreen mode

✨ Preview Screens

πŸ’» Input Form
Input Window Preview
The StudentApp screen at launch, with fields for name, subject, and marks.


πŸ“Š Average + Result View
Result Preview
The user adds multiple marks, and the app calculates the average and displays the result.


πŸ“ CSV Export Confirmation
CSV file Preview
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

Top comments (0)