title: Convert a string to base64
body: <p>I need a simple thing: encode a string in base64. I found an example:</p>
  
  <pre><code>extern crate serialize;
  
  use serialize::base64::{mod, ToBase64};
  use serialize::hex::FromHex;
  
  fn main() {
      let input = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
      let result = input.from_hex().unwrap().as_slice().to_base64(base64::STANDARD);
      println!("{}", result);
  }
  </code></pre>
  
  <p>Which <strong>seams</strong> to work but I don't understand why input contains only characters in HEX. Moreover, this Python code produces a different result:</p>
  
  <pre><code>base64.b64encode(input) # =&gt;
  'NDkyNzZkMjA2YjY5NmM2YzY5NmU2NzIwNzk2Zjc1NzIyMDYyNzI2MTY5NmUyMDZjNjk2YjY1MjA2MTIwNzA2ZjY5NzM2ZjZlNmY3NTczMjA2ZDc1NzM2ODcyNmY2ZjZk'
  </code></pre>
  
  <p>So I decided to do the following:</p>
  
  <pre><code>  //....
      let input = "some string 123";
      let result2 = input.unwrap().as_slice().to_base64(base64::STANDARD);
      let result3 = input.as_slice().to_base64(base64::STANDARD);
  </code></pre>
  
  <p>And it didn't compile due to the errors:</p>
  
  <pre><code>error: type `&amp;str` does not implement any method in scope named `unwrap`
  test1.rs:9     let result2 = input.unwrap().as_slice().to_base64(base64::STANDARD);
                                     ^~~~~~~~
  test1.rs:9:34: 9:44 error: multiple applicable methods in scope [E0034]
  </code></pre>
  
  <p>So how do I encode a simple string in base64?</p>