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?

  • InternetCitizen2@lemmy.worldOP
    link
    fedilink
    arrow-up
    3
    ·
    8 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)@lemmy.mlM
      link
      fedilink
      English
      arrow-up
      2
      ·
      8 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);
      }