How to handle .read_line error?

The code I wrote has errors with some notes from the compiler, but I don't understand them. Here is the code I attempted to write. I will attach the errors in the next part

fn main(){
    let mut pnls = String::new();

        .read_line(&mut pnls),
        .expect("Thats wrong input");

    let pnls: i32 = match pnls.trim().parse(){
        Ok(num)=> num,
        Err(_) => continue,

    if pnls == 500 {
        println!("You're account was suspended");
    } else {println!("That is not our CEO")};

I don't understand why this is causing an error even though the use of ',' is in accordance with the guidelines

.read_line(&mut pnls),
  |                              ^ expected one of `.`, `;`, `?`, `}`, or an operator

It doesn't expect a comma at the end of that line. You can just remove it.

1 Like

Commas are separating the possible next characters, none of which are a comma.

Anyway, just delete the comma. "Something I could parse starts with one of these" doesn't mean "anything starting with one of these parses and makes sense." And those character list errors more generally are about as low-quality as Rust errors get - "we failed to lex and couldn't figure out enough context to give you a higher level, human friendly error."


Oh, maybe you're thinking that a comma is in the list above? It's not. It's just a separator between the chars that are allowed: . ; ? }

Notice that on the next line you start with a period, which is one of the chars it expects.

Earlier, I thought that there should be a comma there. After I tried removing it, the program ran smoothly

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.