this post was submitted on 25 Mar 2024
9 points (100.0% liked)

Rust

5953 readers
11 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hello All:

I am working on rust problems here. In the second question I solved it by simply adding the return statement for the function to modify. I am not sure what the lesson in ownership to walk away with in this problem. Any guidance?

top 2 comments
sorted by: hot top controversial new old
[โ€“] fil@programming.dev 7 points 7 months ago (1 children)

By adding the return statement you pass the ownership of the string back to main. The unmodified function just took the ownership of the string and deallocated it after printing. Hope this helps

[โ€“] InternetCitizen2@lemmy.world 2 points 7 months ago

Yeah thanks!