4

>= rant
While its really hard to get code wrong in Rust, it is also really hard to get code right in Rust. It took me a considerably long time to write a code which returns the first word in the sentence

I felt the borrow checker introduces a steep learning curve into Rust which is otherwise a beautiful language according to me. C++, my current favorite language, also suffers the same problem with respect to certain language features.

Comments
  • 2
    Your first word function returns reference to a range of characters(string slice, or &str) from a String type. So first_word depends on input_string being untouched.

    Clear(): Truncates this String, removing all contents.

    You are basically emptying a string then trying to print it. It doesn’t make sense at all. What is your aim with clear method there?
  • 0
    Join the club of I love Rust but still can't get it right
  • 0
    @aviophile
    I was trying to understand this first_word example from the Rust documentation

    https://doc.rust-lang.org/book/...

    And hence the code!
Add Comment