1use std::io; #[cfg(feature = "calculate")]
4pub fn calculate(num1: f64, num2: f64, operator: &str) -> Result<f64, String> {
5 match operator {
6 "+" => Ok(num1 + num2),
7 "-" => Ok(num1 - num2),
8 "*" => Ok(num1 * num2),
9 "/" => {
10 if num2 == 0.0 {
11 Err(String::from("Division by zero is not allowed!"))
12 } else {
13 Ok(num1 / num2)
14 }
15 }
16 _ => Err(String::from("Invalid operator! Please use +,-,*,/."))
17 }
18}
19
20#[cfg(feature = "input")]
21pub fn get_input(prompt: &str) -> String {
22 println!("{}", prompt);
23 let mut input = String::new();
24 io::stdin()
25 .read_line(&mut input)
26 .expect("Failed to read line");
27 input.trim().to_string()
28}
29
30#[cfg(feature = "hello")]
31pub fn say_hello(name: &str) -> String {
32 format!("Hello, {}", name)
33}
34
35#[cfg(feature = "bye")]
36pub fn say_goodbye(name: &str) -> String {
37 format!("Goodbye, {}", name)
38}