Content deleted Content added
m Open access bot: url-access=subscription, hdl, arxiv, doi updated in citation with #oabot. |
these are super verbose and does not accurately represent the majority of Rust code out there |
||
Line 141:
<syntaxhighlight lang="rust">
fn main() {
let foo
println!("The value of foo is {foo}");
}
Line 151:
fn main() {
// This code would not compile without adding "mut".
let mut foo
println!("The value of foo is {foo}");
foo = 20;
Line 162:
<syntaxhighlight lang="rust">
fn main() {
let foo
// This will output "The value of foo is 10"
println!("The value of foo is {foo}");
let foo
// This will output "The value of foo is 20"
println!("The value of foo is {foo}");
Line 175:
<syntaxhighlight lang="rust">
fn main() {
let letters
let letters
}
</syntaxhighlight>
Line 186:
<syntaxhighlight lang="rust">
fn main() {
let x
println!("this is inside the block");
1 + 2
Line 208:
<syntaxhighlight lang="rust">
fn main() {
let x
if x > 5 {
println!("value is greater than five");
Line 227:
<syntaxhighlight lang="rust">
fn main() {
let x
let new_x
println!("{new_x}");
}
Line 239:
fn main() {
// Iterate over all integers from 4 to 10
let mut value
while value <= 10 {
println!("value = {value}");
Line 276:
<syntaxhighlight lang="rust">
fn main() {
let value
let mut x
let y = loop {
x *= 10;
Line 286:
println!("largest power of ten that is smaller than or equal to value: {y}");
let mut up
'outer: loop {
let mut down
loop {
if up > 100 {
Line 350:
let tuple: (u32, bool) = (3, true);
let array: [i8; 5] = [1, 2, 3, 4, 5];
let value
let value
</syntaxhighlight>
Line 372:
fn main() {
let s
print_string(s); // s consumed by print_string
// s has been moved, so cannot be used any more
Line 387:
fn main() {
let s
print_string(&s); // s borrowed by print_string
print_string(&s); // s has not been consumed; we can call the function many times
Line 406:
<syntaxhighlight lang="rust">
fn main() {
let x
// |
let r
// | |
println!("r: {}", r); // | |
Line 420:
<syntaxhighlight lang="rust">
fn main() {
let r
// |
{ // |
let x
r = &x; // ERROR: x does | |
} // not live long -| |
Line 581:
fn main() {
let x
println!("{x}"); // prints 6
}
|