Skip to content

I still don’t understand the * operator in Rust

micouy.github.io
2 pointsmicouay1 comment
On HN

Comments

You have to understand the difference between a move and a copy. "let b = a" can have 2 meaning - either copy a value to b if a supports copy or move the value a to b and now you cannot use a anymore. Similarly if you did "let a = *b" (where b is a reference) you are doing either a move or a copy depending on b's type. If b doesnt support copy then this will fail to compile as you are trying to move from a reference which is not possible as moving requires ownership of the value and the reference only borrowed it.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.