title: Why unable to parse a string | Rust
body: <p>I am making decimal to binary conversion program. Why am i unable to parse a string into a number? <code>binary_vec[i]</code> is a <code>character</code>. I applied <code>to_string()</code> method to convert it into a string because <code>parse()</code> doesn't apply to a character, but it still giving me an error.</p>
  
  <pre><code>use std::io;
  
  fn main() {
      let mut binary = String::new();
      println!("Enter a decimal: ");
      io::stdin().read_line(&amp;mut binary)
          .ok()
          .expect("Couldn't read line");
      println!("{}",to_decimal(binary));
  
  }
  
  fn to_decimal(mut binary_str:String) -&gt; String {
      let mut binary_no: u32 = binary_str.trim().parse().expect("invalid input");
      if binary_no == 0 {
          format!("{}",binary_no)
                  } 
      else {
          let mut bits = String::new();
          let mut binary_vec: Vec&lt;char&gt; = binary_str.chars().collect();
          let mut result = 0;
          let mut i = 0;
          while i &lt;=binary_str.len()-2{
              let mut result = result + (binary_vec[i].to_string().parse::&lt;u32&gt;().unwrap() * 2^(i as u32));
              i = i +1;
          }
          format!("{}",result)
          }
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code> Compiling sixteen v0.1.0 (C:\Users\Muhammad.3992348\Desktop\rust\hackathon\sixteen)
  warning: unused variable: `bits`
    --&gt; src\main.rs:19:17
     |
  19 |         let mut bits = String::new();
     |                 ^^^^ help: consider prefixing with an underscore: `_bits`
     |
     = note: #[warn(unused_variables)] on by default
  
  warning: unused variable: `result`
    --&gt; src\main.rs:24:21
     |
  24 |             let mut result = result + (binary_vec[i].to_string().parse::&lt;u32&gt;().unwrap() * 2^(i as u32));
     |                     ^^^^^^ help: consider prefixing with an underscore: `_result`
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:13:15
     |
  13 | fn to_decimal(mut binary_str:String) -&gt; String {
     |               ----^^^^^^^^^^
     |               |
     |               help: remove this `mut`
     |
     = note: #[warn(unused_mut)] on by default
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:14:9
     |
  14 |     let mut binary_no: u32 = binary_str.trim().parse().expect("invalid input");
     |         ----^^^^^^^^^
     |         |
     |         help: remove this `mut`
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:19:13
     |
  19 |         let mut bits = String::new();
     |             ----^^^^
     |             |
     |             help: remove this `mut`
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:20:13
     |
  20 |         let mut binary_vec: Vec&lt;char&gt; = binary_str.chars().collect();
     |             ----^^^^^^^^^^
     |             |
     |             help: remove this `mut`
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:21:13
     |
  21 |         let mut result = 0;
     |             ----^^^^^^
     |             |
     |             help: remove this `mut`
  
  warning: variable does not need to be mutable
    --&gt; src\main.rs:24:17
     |
  24 |             let mut result = result + (binary_vec[i].to_string().parse::&lt;u32&gt;().unwrap() * 2^(i as u32));
     |                 ----^^^^^^
     |                 |
     |                 help: remove this `mut`
  
      Finished dev [unoptimized + debuginfo] target(s) in 1.04s
       Running `target\debug\sixteen.exe`
  Enter a decimal:
  100
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', src\libcore\result.rs:997:5
  note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
  error: process didn't exit successfully: `target\debug\sixteen.exe` (exit code: 101)
  </code></pre>
  
  <p>Edit:
  I have input 100 and I expect to get 4 at output.</p>