0

I'd like to compare 2 strings in Rust. I'm pretty sure that both "strings" are already strings, but no matter what the user enters, it always chooses the Blacklist mode!

Here is what I've tried:

//Imports
use std::io;

fn main() {
    //Greeting
    println!("[INFO] Welcome to Tracer!\n");
    println!("[ ?? ] Use Blacklist mode ? [Y/n]");

    //Get user input
    let users_choice = get_input();

    //Check if user wants to run in Blacklist Mode
    if users_choice == ToString::to_string("n") || users_choice == ToString::to_string("N") {
        //User wants to use Whitelist mode
        trace_network(0);
    } else {
        //User wants to use Blacklist mode
        trace_network(1);
    }
}

fn get_input() -> String {

    //Creating changeable var
    let mut user_input = String::new();

    //Read Input; On Error drop MSG
    io::stdin().read_line(&mut user_input)
        .expect("[FAIL] Failed to read line");

    println!("[INFO] Your input was: >{}<", user_input);

    return user_input;
}

fn trace_network(mode:i32) {
    println!("[INFO] Starting trace !!! {}", mode);

    //Print wich mode was choosen
    if mode == 0 {
        println!("[INFO] Whitelistmode!");
    } else {
        println!("[INFO] Blacklistmode!");
    }
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
MrFlyingToasterman
  • 217
  • 1
  • 6
  • 14

0 Answers0