fn tokenize(unit: &str) -> Vec<Token> {
    let mut tokens = Vec::new();
    let mut token = String::new();
    for c in unit.chars() {
        match c {
            '*' | '/' | '^' | '(' | ')' => {
                if !token.is_empty() {
                    tokens.push(Token::Value(token.clone()));
                    token.clear();
                }
                match c {
                    '*' => tokens.push(Token::Mul),
                    '/' => tokens.push(Token::Div),
                    '^' => tokens.push(Token::Pow),
                    '(' => tokens.push(Token::LParen),
                    ')' => tokens.push(Token::RParen),
                    _ => unreachable!("invalid unit operator"),
                }
            }
            other if !other.is_whitespace() => {
                token.push(other);
            }
            _ => assert!(c.is_whitespace()),
        }
    }
    // Last token
    if !token.is_empty() {
        tokens.push(Token::Value(token));
    }
    return tokens;
}
/// Transform a string to a stream of tokens
Transform a string to a stream of tokens
Transform a string to a stream of tokens
fn tokenize(unit: &str) -> Vec<Token> {
    let mut tokens = Vec::new();
    let mut token = String::new();
    for c in unit.chars() {
        match c {
            '*' | '/' | '^' | '(' | ')' => {
                if !token.is_empty() {
                    tokens.push(Token::Value(token.clone()));
                    token.clear();
                }
                match c {
                    '*' => tokens.push(Token::Mul),
                    '/' => tokens.push(Token::Div),
                    '^' => tokens.push(Token::Pow),
                    '(' => tokens.push(Token::LParen),
                    ')' => tokens.push(Token::RParen),
                    _ => unreachable!("invalid unit operator"),
                }
            }
            other if !other.is_whitespace() => {
                token.push(other);
            }
            _ => assert!(c.is_whitespace()),
        }
    }
    // Last token
    if !token.is_empty() {
        tokens.push(Token::Value(token));
    }
    return tokens;
}
fn tokenize ( unit : & str ) -> Vec < Token > { let mut tokens = Vec :: new ( ) ; let mut token = String :: new ( ) ; for c in unit . chars ( ) { match c { '*' | '/' | '^' | '(' | ')' => { if ! token . is_empty ( ) { tokens . push ( Token :: Value ( token . clone ( ) ) ) ; token . clear ( ) ; } match c { '*' => tokens . push ( Token :: Mul ) , '/' => tokens . push ( Token :: Div ) , '^' => tokens . push ( Token :: Pow ) , '(' => tokens . push ( Token :: LParen ) , ')' => tokens . push ( Token :: RParen ) , _ => unreachable ! ( " " ) , } } other if ! other . is_whitespace ( ) => { token . push ( other ) ; } _ => assert ! ( c is_whitespace ( ) ) , } } // Last token if ! token . is_empty ( ) { tokens . push ( Token :: Value ( token ) ) ; } return tokens ; }
Transform a string to a stream of tokens
Transform a string to a stream of tokens
unit
&str