I am confused by the difference between ::
and .
. They look the same except that their syntax are different.
let mut guess = String::new(); io::stdin().read_line(&mut guess) .expect("Failed to read line");
"Programming a Guessing Game" from The Rust Programming Language
In the above case, I access the function new()
in String
. What is the difference between String::new()
and String.new()
? Is .
only for methods?
.
is used when you have a value on the left-hand-side. ::
is used when you have a type or module.
Or: .
is for value member access, ::
is for namespace member access.