rust - How can I concatenate something to the front of a string? -


i keep getting error "use of moved value".

let mut s = "s".to_string(); s = s + &s; 

think + desugars to:

s = s.add(&s); 

now add from add trait , this:

fn add(self: string, rhs: &str) -> string; 

the use of self means taking ownership of string; can’t pass reference second argument, because isn’t yours more.

you might think it’d ok doing this, it’s not; whole class unsound, constituting mutable aliasing—both mutable , immutable reference same thing existing @ same time. specific case, 1 way imagine going wrong if permitted if string pushing reallocate string; rhs conceivably pointing non-existent memory when went use it.


Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -