[SOLVED] Concatening a string which is a member of struct


#1

Hi There

i have a struct:

Struct Foo {
   bar: String 
}

impl Foo {
  fn bar(&self){
    let baz = *&self.bar + "foo" // (the "foo" part isn't important here)
  }
}

I get

cannot move out of borrowed content

for *&self.bar

Is there a way I can get the value so I can concatenate it with foo?
`


#2
let baz = format!("{}foo", self.bar);

#3

Hey thanks for the quick reply. What if “foo” is stored in a variable?

EDIT: Nevamind. i am checking the docs :smiley:


#4

In this case the format would need to take two variables, i.e. 3 params in total.


#5

Yah. Got it working. Thanks :slight_smile: