pub struct Operators {
pub addition: char,
pub subtraction: char,
pub multiplication: char,
pub division: char,
pub modulo: char,
}Expand description
A struct containing basic math operators.
§Examples
use C4lc::Operators;
fn main() {
let ops = Operators::new();
println!("Type your number to be added\n");
let mut input = String::new();
std::io::stdin().read_line(&mut input).expect("Failed to read input");
let input: f64 = match input.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Not a valid input!");
return;
}
};
println!("\nType your second number\n");
let mut input2 = String::new();
std::io::stdin().read_line(&mut input2).expect("Failed to read input");
let input2: f64 = match input2.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("Not a valid input!");
return;
}
};
let answer = match ops.addition {
'+' => input + input2, // matches the char and if the wrong symbol is used, the result will be wrong
_ => input,
};
println!("\n{} + {} is: {}", input, input2, answer);
}Fields§
§addition: char§subtraction: char§multiplication: char§division: char§modulo: charImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Operators
impl RefUnwindSafe for Operators
impl Send for Operators
impl Sync for Operators
impl Unpin for Operators
impl UnsafeUnpin for Operators
impl UnwindSafe for Operators
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more