What is * in rust

I just got this issue resolved by using * that casted the &u8 to u8

main(){
      let it : &[u8] = &vec!(8, 9);
      it.iter().map(|it| *it).for_each(|it|  println!("{}/2 = {}", it, f64::from(it)/2_f64));
}

But did not understand the meaning of * and what it exactly did?

It's the dereference operator. It turns a &T into a T.

(Ok, it's slightly more complex than that; it calls Deref::deref on anything that implements Deref - &T is just a very common case.)

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.