Start with the idea
A method call uses dot syntax, and Rust automatically borrows or dereferences the receiver when the signature makes that unambiguous. Chaining is readable when each step produces the value the next step expects. Watch ownership: some methods borrow the receiver, while others consume it and return a new value.
Start at the receiver, the value to the left of the dot. In name.trim(), trim borrows the string and returns a slice (&str) of its contents; it does not edit name. The next call, to_uppercase(), reads that slice and creates a new String. You can still print the original value after both calls. A chain is easiest to reason about when you can name the type after each step: String → &str → String.
Method syntax is a convenient way to pass the receiver as the first argument.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.