cross-posted from: https://lemmy.world/post/13508677

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?

  • @InternetCitizen2OP
    link
    39 months ago

    Yes that is the question in question. I just was not sure what principle of ownership was in play to answer it since just adding the returns fixed the question. Perhaps it was supposed to be for another problem set and it got posted with these by accident.

    • maegul (he/they)M
      link
      fedilink
      English
      29 months ago

      Yea, something seems off. Probably best to move on.

      If you want a problem … here’s my quick modification to make it about ownership. You can modify both functions. By the sounds of it though you might be on top of this.

      fn main() {
          let s1 = String::from("Hello world");
          let _ = take_ownership(s1);
      
          println!("{}", s1);
      }
      
      fn take_ownership(s: String) {
          println!("{}", s);
      }