title: On Rust Setters
body: <p>I have looked on Stack Overflow for ways to set values within a declared mutable struct. The answers did not look straightforward, and for me, strayed too far away from simplicity that I enjoy. I eventually found out from tinkering around that this code works as desired:</p>
  
  <pre><code>struct FooStruct {
      bar: i32,
  }
  
  impl FooStruct {
  
      fn set(&amp;mut self, val: i32){
          //*self.first_name_mut() = val;
          *(&amp;mut self.bar) = val;
      }
  
  }
  
  fn main() {
      let mut k = 45;
      let mut my_person = FooStruct { bar: 2};
  
      println!("Fn: {}", my_person.bar);
      my_person.set(k);
      println!("Fn: {}", my_person.bar); //value is printed as 45
      k = 33; // set k-value
      println!("Fn: {}", my_person.bar); //the value in the struct remains as 45, unchanged
  }
  </code></pre>
  
  <p>Notice how simple it is to implement a setter:</p>
  
  <pre><code>*(&amp;mut self.bar) = val;
  </code></pre>
  
  <p>My question is: is there a catch to this simplicity of setting a value? People have went as far as creating macros for getting/setting, so I'm wondering why this method isn't used. I'm coming from Java-land, where setting is a mindless deal (this.value = input); upon arrival where rustaceans live, I expected OOP-like features to be a nuisance to implement.</p>
  
  <p>While I hope this post helps people implement a setter, I also want an experienced user to explain what the line of code above is doing as well as any pitfalls that I have not (possibly yet) seen.</p>