Simple function to create Tokens from user input I am new to programming in Rust and as an exercise I was making a simple Lottery checker program.
It has a simple menu, the user enters a number for the corresponding option such as 'Add a line', 'Check if I am a winner' etc.

So all the user needs to do is enter either a number or a 'y' or 'n'.
So I created a simple Token to see if they have either entered a number or a char and return a token.

This works fine. But as I am on my own I was looking for feedback so that I can improve my skills.

use std::io::{self, Write};

#[derive(Debug, PartialEq)]
enum Token {
    Number(i32),
    Decision(char),
    // Error(String),
}

fn get_number(val: &amp;str) -&gt; Option&lt;Token&gt; {
    if let Some(x) = val.split_whitespace().next() {
        let y: i32 = match x.parse() {
            Ok(val) =&gt; val,
            Err(_error) =&gt; return None,
        };
        Some(Token::Number(y))
    } else {
        None
    }
}

fn get_char(val: &amp;str) -&gt; Option&lt;Token&gt; {
    if let Some(x) = val.split_whitespace().next() {
        let y: char = match x.parse() {
            Ok(val) =&gt; val,
            Err(_error) =&gt; return None,
        };
        Some(Token::Decision(y))
    } else {
        None
    }
}

fn get_input(msg: &amp;str, input: &amp;str) -&gt; Option&lt;Token&gt; {
    print!("{}\n{}", msg, "&gt;&gt; ");
    io::stdout().flush().unwrap();

    let buffer = input;
    //let mut buffer = String::new();
    // while buffer.is_empty() {
    // io::stdin()
    // .read_line(&amp;mut buffer)
    // .expect("GET_INPUT: error reading line.");

    //  buffer = buffer
    // .trim()
    // .parse()
    //  .expect("GET_INPUT: error parsing buffer");

    // if buffer.is_empty() {
    //     println!("You didn't enter anything.\n{}", &amp;msg)
    // };
    // }

    if let Some(token) = get_number(&amp;buffer) {
        if let Token::Number(val) = token {
            return Some(Token::Number(val));
        }
    } else if let Some(token) = get_char(&amp;buffer) {
        if let Token::Decision(val) = token {
            return Some(Token::Decision(val));
        }
    }
    None
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn get_input_test() {
        let chars1 = "@  n 23";
        let chars2 = "34 n 23";
        let chars3 = "$ ££$^\"3234y n 23";
        let chars4 = "";
        let chars5 = "      ";

        assert_eq!(Some(Token::Decision('@')), get_input("", &amp;chars1));
        assert_eq!(Some(Token::Number(34)), get_input("", &amp;chars2));
        assert_eq!(Some(Token::Decision('$')), get_input("", &amp;chars3));
        assert_eq!(None, get_input("", &amp;chars4));
        assert_eq!(None, get_input("", &amp;chars5));
    }

}



To get some more fine grain control I understand I will need to use an Iterator, is this correct?
It's not clear whether you want to support only y, n and numbers as your question states, or any characters besides y &amp; n as your code implies :)

Basically you can divide the problem to two sub problems:


Split the input string to words I'm using the split methods from std but if you have more complex requirements, you can use the regex crate 
Map the words to tokens. A simple equality check (==) or match is enough. There is no need to parse() everything. 


As you've not specified what's allowed as a delimiter, I'll assume that it's whitespace. 

#[derive(Debug)]
enum InputToken {
    Number(i64),
    Boolean(bool),
    Error(String),
}

fn main() {
    let input = "1 -2 +4 y n &amp; abc";
    let tokens = input.split_whitespace();

    for x in tokens {
        println!("{:?}", parse_token(x));
    }
}

fn parse_token(input: &amp;str) -&gt; InputToken {
    match input {
        "y" =&gt; InputToken::Boolean(true),
        "n" =&gt; InputToken::Boolean(false),
        token =&gt; match token.parse::&lt;i64&gt;() {
            Ok(num) =&gt; InputToken::Number(num),
            Err(e) =&gt; InputToken::Error(format!("Invalid input token [{}]: {:?}", token, e))
    }
}


}