Ownership error

⚓ Rust    📅 2025-09-17    👤 surdeus    👁️ 1      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Ownership error

I have a function that takes one parameter, a string and returns a string reference of the clone of that string parameter. The binary however doesn't compile. The debugger requests that I change the string reference. What Im I fundamentally missing in this setup. Here is the code

fn taker (S:String) -> &String {
let c = S.clone();
&c
}

fn main () {
let V = taker("Value".to_string());
println!(".. {:?}",V);
}

17581064079104028335237673956923

4 posts - 4 participants

Read full topic

🏷️ Rust_feed