Content deleted Content added
Citation bot (talk | contribs) Removed URL that duplicated identifier. | Use this bot. Report bugs. | #UCB_CommandLine |
No edit summary |
||
Line 87:
<syntaxhighlight lang="rust">
fn main() {
let foo: i32 = 10;
println!("The value of foo is {foo}");
}
Line 97:
fn main() {
// This code would not compile without adding "mut".
let mut foo: i32 = 10;
println!("The value of foo is {foo}");
foo = 20;
Line 108:
<syntaxhighlight lang="rust">
fn main() {
let foo: i32 = 10;
// This will output "The value of foo is 10"
println!("The value of foo is {foo}");
let foo: i32 = foo * 2;
// This will output "The value of foo is 20"
println!("The value of foo is {foo}");
Line 121:
<syntaxhighlight lang="rust">
fn main() {
let letters: str = "abc";
let letters: usize = letters.len();
}
</syntaxhighlight>
Line 132:
<syntaxhighlight lang="rust">
fn main() {
let x: i32 = {
println!("this is inside the block");
1 + 2
Line 154:
<syntaxhighlight lang="rust">
fn main() {
let x: i32 = 10;
if x > 5 {
println!("value is greater than five");
Line 173:
<syntaxhighlight lang="rust">
fn main() {
let x: i32 = 10;
let new_x: i32 = if x % 2 == 0 { x / 2 } else { 3 * x + 1 };
println!("{new_x}");
}
Line 185:
fn main() {
// Iterate over all integers from 4 to 10
let mut value: i32 = 4;
while value <= 10 {
println!("value = {value}");
Line 222:
<syntaxhighlight lang="rust">
fn main() {
let value: i32 = 456;
let mut x: i32 = 1;
let y = loop {
x *= 10;
Line 232:
println!("largest power of ten that is smaller than or equal to value: {y}");
let mut up: i32 = 1;
'outer: loop {
let mut down: i32 = 120;
loop {
if up > 100 {
Line 296:
let tuple: (u32, i64) = (3, -3);
let array: [i8; 5] = [1, 2, 3, 4, 5];
let
let value: i8 =
</syntaxhighlight>
Line 318 ⟶ 317:
fn main() {
let s: String = String::from("Hello, World");
print_string(s); // s consumed by print_string
// s has been moved, so cannot be used any more
Line 333 ⟶ 332:
fn main() {
let s: String = String::from("Hello, World");
print_string(&s); // s borrowed by print_string
print_string(&s); // s has not been consumed; we can call the function many times
Line 352 ⟶ 351:
<syntaxhighlight lang="rust">
fn main() {
let x: i32 = 5;
// |
let r: &i32 = &x;
// | |
println!("r: {}", r); // | |
Line 366 ⟶ 365:
<syntaxhighlight lang="rust">
fn main() {
let r: &i32;
// |
{ // |
let x: i32 = 5;
r = &x; // ERROR: x does | |
} // not live long -| |
Line 707 ⟶ 706:
fn main() {
let x: i32 = sum!(1, 2, 3);
println!("{x}"); // prints 6
}
|