"Let x = ~ 10;" deprecated in Rust?
I read this tutorial and tried the following Rust code:
fn main() {
let x = ~10;
println!("{:d}", *x);
}
But the compiler complains:
rustc 1.16.0 (30cf806ef 2017-03-10) error: expected expression, found `~` --> <anon>:2:13 | 2 | let x = ~10; | ^ error: unknown format trait `d` --> <anon>:3:22 | 3 | println!("{:d}", *x); | ^^
Is it let x = ~10;
already deprecated?
+3
source to share
1 answer
It is very outdated. Rust 1.0 was released on 2015-05-15. This syntax was removed a few months earlier. This means that your tutorial has not been updated for a long time; In fact, this file was last updated on 2014-01-28! Not a good sign.
Not an outdated version of your code:
fn main() {
let x = Box::new(10);
println!("{}", x);
}
- The sigil has
~
been replaced with specific data structures. In this caseBox
. - The format specifier
:d
no longer exists. Just useDisplay
formatter{}
. - There is no need to dereference the number in the box.
Use the official sources instead of some "outdated" link:
+8
source to share