mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 13:49:19 +00:00
Use inline format argument syntax
This commit is contained in:
parent
ce7ffcd8e9
commit
73443630e8
@ -9,5 +9,5 @@ fn main() {
|
||||
for x in option {
|
||||
res += x;
|
||||
}
|
||||
println!("{}", res);
|
||||
println!("{res}");
|
||||
}
|
||||
|
||||
@ -14,15 +14,15 @@ fn main() {
|
||||
-1, -2, -3
|
||||
-4, -5, -6
|
||||
];
|
||||
println!("My array! Here it is: {:?}", my_arr);
|
||||
println!("My array! Here it is: {my_arr:?}");
|
||||
|
||||
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
|
||||
println!("This Vec is empty, see? {:?}", my_empty_vec);
|
||||
println!("This Vec is empty, see? {my_empty_vec:?}");
|
||||
|
||||
let mut value_a = 45;
|
||||
let mut value_b = 66;
|
||||
// Let's swap these two!
|
||||
value_a = value_b;
|
||||
value_b = value_a;
|
||||
println!("value a: {}; value b: {}", value_a, value_b);
|
||||
println!("value a: {value_a}; value b: {value_b}");
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ impl FromStr for Person {
|
||||
|
||||
fn main() {
|
||||
let p = "Mark,20".parse::<Person>().unwrap();
|
||||
println!("{:?}", p);
|
||||
println!("{p:?}");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -29,7 +29,7 @@ impl State {
|
||||
}
|
||||
|
||||
fn echo(&self, s: String) {
|
||||
println!("{}", s);
|
||||
println!("{s}");
|
||||
}
|
||||
|
||||
fn move_position(&mut self, p: Point) {
|
||||
|
||||
@ -12,7 +12,7 @@ pub fn generate_nametag_text(name: String) -> Option<String> {
|
||||
// Empty names aren't allowed.
|
||||
None
|
||||
} else {
|
||||
Some(format!("Hi! My name is {}", name))
|
||||
Some(format!("Hi! My name is {name}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ fn main() {
|
||||
println!("You can't afford that many!");
|
||||
} else {
|
||||
tokens -= cost;
|
||||
println!("You now have {} tokens.", tokens);
|
||||
println!("You now have {tokens} tokens.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
fn main() {
|
||||
let answer = square(3);
|
||||
println!("The square of 3 is {}", answer);
|
||||
println!("The square of 3 is {answer}");
|
||||
}
|
||||
|
||||
fn square(num: i32) -> i32 {
|
||||
|
||||
@ -22,5 +22,5 @@ fn main() {
|
||||
let string2 = "xyz";
|
||||
|
||||
let result = longest(string1.as_str(), string2);
|
||||
println!("The longest string is '{}'", result);
|
||||
println!("The longest string is '{result}'");
|
||||
}
|
||||
|
||||
@ -23,5 +23,5 @@ fn main() {
|
||||
let string2 = String::from("xyz");
|
||||
result = longest(string1.as_str(), string2.as_str());
|
||||
}
|
||||
println!("The longest string is '{}'", result);
|
||||
println!("The longest string is '{result}'");
|
||||
}
|
||||
|
||||
@ -8,11 +8,11 @@ fn main() {
|
||||
|
||||
let vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
|
||||
vec1.push(88);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
|
||||
@ -10,11 +10,11 @@ fn main() {
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
// Do not change the following line!
|
||||
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
|
||||
println!("{} has length {} content `{vec0:?}`", "vec0", vec0.len());
|
||||
|
||||
vec1.push(88);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
|
||||
@ -10,11 +10,11 @@ fn main() {
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
|
||||
vec1.push(88);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
}
|
||||
|
||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||
|
||||
@ -11,11 +11,11 @@ fn main() {
|
||||
|
||||
let mut vec1 = fill_vec(vec0);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
|
||||
vec1.push(88);
|
||||
|
||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||
println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
|
||||
}
|
||||
|
||||
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
|
||||
|
||||
@ -21,5 +21,5 @@ fn get_char(data: String) -> char {
|
||||
fn string_uppercase(mut data: &String) {
|
||||
data = &data.to_uppercase();
|
||||
|
||||
println!("{}", data);
|
||||
println!("{data}");
|
||||
}
|
||||
|
||||
@ -8,5 +8,5 @@ fn main() {
|
||||
let cat = ("Furry McFurson", 3.5);
|
||||
let /* your pattern here */ = cat;
|
||||
|
||||
println!("{} is {} years old.", name, age);
|
||||
println!("{name} is {age} years old.");
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ fn main() {
|
||||
let child_numbers = // TODO
|
||||
joinhandles.push(thread::spawn(move || {
|
||||
let sum: u32 = child_numbers.iter().filter(|n| *n % 8 == offset).sum();
|
||||
println!("Sum of offset {} is {}", offset, sum);
|
||||
println!("Sum of offset {offset} is {sum}");
|
||||
}));
|
||||
}
|
||||
for handle in joinhandles.into_iter() {
|
||||
|
||||
@ -26,7 +26,7 @@ enum Planet {
|
||||
|
||||
impl Planet {
|
||||
fn details(&self) {
|
||||
println!("Hi from {:?}!", self)
|
||||
println!("Hi from {self:?}!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
fn main() {
|
||||
let answer = current_favorite_color();
|
||||
println!("My current favorite color is {}", answer);
|
||||
println!("My current favorite color is {answer}");
|
||||
}
|
||||
|
||||
fn current_favorite_color() -> String {
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
// I AM NOT DONE
|
||||
|
||||
fn string_slice(arg: &str) {
|
||||
println!("{}", arg);
|
||||
println!("{arg}");
|
||||
}
|
||||
fn string(arg: String) {
|
||||
println!("{}", arg);
|
||||
println!("{arg}");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@ -41,7 +41,7 @@ mod tests {
|
||||
fn unit_structs() {
|
||||
// TODO: Instantiate a unit-like struct!
|
||||
// let unit_like_struct =
|
||||
let message = format!("{:?}s are fun!", unit_like_struct);
|
||||
let message = format!("{unit_like_struct:?}s are fun!");
|
||||
|
||||
assert_eq!(message, "UnitLikeStructs are fun!");
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ fn main() {
|
||||
for i in 0..10 {
|
||||
thread::spawn(move || {
|
||||
thread::sleep(Duration::from_millis(250));
|
||||
println!("thread {} is complete", i);
|
||||
println!("thread {i} is complete");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
|
||||
|
||||
thread::spawn(move || {
|
||||
for val in &qc1.first_half {
|
||||
println!("sending {:?}", val);
|
||||
println!("sending {val:?}");
|
||||
tx.send(*val).unwrap();
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
@ -39,7 +39,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
|
||||
|
||||
thread::spawn(move || {
|
||||
for val in &qc2.second_half {
|
||||
println!("sending {:?}", val);
|
||||
println!("sending {val:?}");
|
||||
tx.send(*val).unwrap();
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
@ -55,10 +55,10 @@ fn main() {
|
||||
|
||||
let mut total_received: u32 = 0;
|
||||
for received in rx {
|
||||
println!("Got: {}", received);
|
||||
println!("Got: {received}");
|
||||
total_received += 1;
|
||||
}
|
||||
|
||||
println!("total numbers received: {}", total_received);
|
||||
println!("total numbers received: {total_received:?}");
|
||||
assert_eq!(total_received, queue_length)
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ impl AppendBar for String {
|
||||
fn main() {
|
||||
let s = String::from("Foo");
|
||||
let s = s.append_bar();
|
||||
println!("s: {}", s);
|
||||
println!("s: {s}");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -6,5 +6,5 @@
|
||||
|
||||
fn main() {
|
||||
x = 5;
|
||||
println!("x has the value {}", x);
|
||||
println!("x has the value {x}");
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
|
||||
fn main() {
|
||||
let x: i32;
|
||||
println!("Number {}", x);
|
||||
println!("Number {x}");
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
fn main() {
|
||||
let x = 3;
|
||||
println!("Number {}", x);
|
||||
println!("Number {x}");
|
||||
x = 5; // don't change this line
|
||||
println!("Number {}", x);
|
||||
println!("Number {x}");
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
fn main() {
|
||||
let number = "T-H-R-E-E"; // don't change this line
|
||||
println!("Spell a Number : {}", number);
|
||||
println!("Spell a Number : {number}");
|
||||
number = 3; // don't rename this variable
|
||||
println!("Number plus two is : {}", number + 2);
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
|
||||
const NUMBER = 3;
|
||||
fn main() {
|
||||
println!("Number {}", NUMBER);
|
||||
println!("Number {NUMBER}");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user