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?

  • maegul (he/they)M
    link
    fedilink
    English
    arrow-up
    2
    ·
    9 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);
    }