How to define a Rust function that consumes a owned String and returns a owned Split?

  Kiến thức lập trình

I want to read one line from stdin, then split it by whitespaces and process these parts.

A simple read_line would work since it returns a owned String:

fn read_line() -> String {
    let mut str: String = String::new();
    stdin().read_line(&mut str).unwrap();
    return str;
}

But I couldn’t make it when I want to consume the String and return a owned Split whose lifetime goes out of the function that creates it.

New contributor

x6eull is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT