GithubHelp home page GithubHelp logo

rust_calc's Introduction

rust_calc

The Rust Calculator project, also known as rust_calc, is a graphical calculator application built with the Rust programming language and GTK toolkit.
It allows users to perform basic arithmetic operations, including addition, subtraction, multiplication, and division.
The calculator features a clean and intuitive graphical user interface, making it easy for users to input expressions and obtain results.
This project includes tests to ensure that the calculator performs the correct operations and handles errors appropriately.
Say NO to 'Legacy code'

Features

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • ... and more

How operations are added to the GUI

 let operations = vec!["+", "-", "*", "/"];
    for (i, operation) in operations.iter().enumerate() {
        let operation = operation.clone();
        let button = Button::with_label(operation);
        let label_clone = Rc::clone(&label);
        button.connect_clicked(move |_| {
            let current_text = label_clone.borrow().text().to_string();
            let new_text = format!("{} {} ", current_text, operation);
            label_clone.borrow_mut().set_text(&new_text);
        });
        grid.attach(&button, 3, i as i32 + 1, 1, 1);
    }

How operations are performed

  match parts[1] {
        "+" => Ok(operand1 + operand2),
        "-" => Ok(operand1 - operand2),
        "*" => Ok(operand1 * operand2),
        "/" => {
            if operand2 != 0.0 {
                Ok(operand1 / operand2)
            } else {
                Err("Division by zero")
            }
        }
        _ => Err("Invalid operator"),
    }

How to Run

Prerequisites

Make sure you have Rust on your machine.

Download the Unix Executable File

This executable file is located in the releases tab, or you can download it here.
It can be created when you run the project and is found at /src/target/debug or /src/target/release depending on how you build it.
To check if your system is Unix based click here.

Run the Project

To run the project, execute the following command:

cargo run

Example

Image

This is a brief example of my project.

rust_calc's People

Contributors

telmo-sousa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.