Use inline format argument syntax

This commit is contained in:
Yuri Astrakhan 2022-10-12 20:19:28 -04:00
parent ce7ffcd8e9
commit 73443630e8
28 changed files with 39 additions and 39 deletions

View File

@ -9,5 +9,5 @@ fn main() {
for x in option { for x in option {
res += x; res += x;
} }
println!("{}", res); println!("{res}");
} }

View File

@ -14,15 +14,15 @@ fn main() {
-1, -2, -3 -1, -2, -3
-4, -5, -6 -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); 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_a = 45;
let mut value_b = 66; let mut value_b = 66;
// Let's swap these two! // Let's swap these two!
value_a = value_b; value_a = value_b;
value_b = value_a; value_b = value_a;
println!("value a: {}; value b: {}", value_a, value_b); println!("value a: {value_a}; value b: {value_b}");
} }

View File

@ -51,7 +51,7 @@ impl FromStr for Person {
fn main() { fn main() {
let p = "Mark,20".parse::<Person>().unwrap(); let p = "Mark,20".parse::<Person>().unwrap();
println!("{:?}", p); println!("{p:?}");
} }
#[cfg(test)] #[cfg(test)]

View File

@ -29,7 +29,7 @@ impl State {
} }
fn echo(&self, s: String) { fn echo(&self, s: String) {
println!("{}", s); println!("{s}");
} }
fn move_position(&mut self, p: Point) { fn move_position(&mut self, p: Point) {

View File

@ -12,7 +12,7 @@ pub fn generate_nametag_text(name: String) -> Option<String> {
// Empty names aren't allowed. // Empty names aren't allowed.
None None
} else { } else {
Some(format!("Hi! My name is {}", name)) Some(format!("Hi! My name is {name}"))
} }
} }

View File

@ -18,7 +18,7 @@ fn main() {
println!("You can't afford that many!"); println!("You can't afford that many!");
} else { } else {
tokens -= cost; tokens -= cost;
println!("You now have {} tokens.", tokens); println!("You now have {tokens} tokens.");
} }
} }

View File

@ -5,7 +5,7 @@
fn main() { fn main() {
let answer = square(3); let answer = square(3);
println!("The square of 3 is {}", answer); println!("The square of 3 is {answer}");
} }
fn square(num: i32) -> i32 { fn square(num: i32) -> i32 {

View File

@ -22,5 +22,5 @@ fn main() {
let string2 = "xyz"; let string2 = "xyz";
let result = longest(string1.as_str(), string2); let result = longest(string1.as_str(), string2);
println!("The longest string is '{}'", result); println!("The longest string is '{result}'");
} }

View File

@ -23,5 +23,5 @@ fn main() {
let string2 = String::from("xyz"); let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str()); result = longest(string1.as_str(), string2.as_str());
} }
println!("The longest string is '{}'", result); println!("The longest string is '{result}'");
} }

View File

@ -8,11 +8,11 @@ fn main() {
let vec1 = fill_vec(vec0); let vec1 = fill_vec(vec0);
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); println!("{} has length {} content `{vec1:?}`", "vec1", vec1.len());
vec1.push(88); 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> { fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

View File

@ -10,11 +10,11 @@ fn main() {
let mut vec1 = fill_vec(vec0); let mut vec1 = fill_vec(vec0);
// Do not change the following line! // 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); 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> { fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

View File

@ -10,11 +10,11 @@ fn main() {
let mut vec1 = fill_vec(vec0); 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); 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> { fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

View File

@ -11,11 +11,11 @@ fn main() {
let mut vec1 = fill_vec(vec0); 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); 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 // `fill_vec()` no longer takes `vec: Vec<i32>` as argument

View File

@ -21,5 +21,5 @@ fn get_char(data: String) -> char {
fn string_uppercase(mut data: &String) { fn string_uppercase(mut data: &String) {
data = &data.to_uppercase(); data = &data.to_uppercase();
println!("{}", data); println!("{data}");
} }

View File

@ -8,5 +8,5 @@ fn main() {
let cat = ("Furry McFurson", 3.5); let cat = ("Furry McFurson", 3.5);
let /* your pattern here */ = cat; let /* your pattern here */ = cat;
println!("{} is {} years old.", name, age); println!("{name} is {age} years old.");
} }

View File

@ -33,7 +33,7 @@ fn main() {
let child_numbers = // TODO let child_numbers = // TODO
joinhandles.push(thread::spawn(move || { joinhandles.push(thread::spawn(move || {
let sum: u32 = child_numbers.iter().filter(|n| *n % 8 == offset).sum(); 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() { for handle in joinhandles.into_iter() {

View File

@ -26,7 +26,7 @@ enum Planet {
impl Planet { impl Planet {
fn details(&self) { fn details(&self) {
println!("Hi from {:?}!", self) println!("Hi from {self:?}!")
} }
} }

View File

@ -6,7 +6,7 @@
fn main() { fn main() {
let answer = current_favorite_color(); let answer = current_favorite_color();
println!("My current favorite color is {}", answer); println!("My current favorite color is {answer}");
} }
fn current_favorite_color() -> String { fn current_favorite_color() -> String {

View File

@ -9,10 +9,10 @@
// I AM NOT DONE // I AM NOT DONE
fn string_slice(arg: &str) { fn string_slice(arg: &str) {
println!("{}", arg); println!("{arg}");
} }
fn string(arg: String) { fn string(arg: String) {
println!("{}", arg); println!("{arg}");
} }
fn main() { fn main() {

View File

@ -41,7 +41,7 @@ mod tests {
fn unit_structs() { fn unit_structs() {
// TODO: Instantiate a unit-like struct! // TODO: Instantiate a unit-like struct!
// let 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!"); assert_eq!(message, "UnitLikeStructs are fun!");
} }

View File

@ -14,7 +14,7 @@ fn main() {
for i in 0..10 { for i in 0..10 {
thread::spawn(move || { thread::spawn(move || {
thread::sleep(Duration::from_millis(250)); thread::sleep(Duration::from_millis(250));
println!("thread {} is complete", i); println!("thread {i} is complete");
}); });
} }

View File

@ -31,7 +31,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
thread::spawn(move || { thread::spawn(move || {
for val in &qc1.first_half { for val in &qc1.first_half {
println!("sending {:?}", val); println!("sending {val:?}");
tx.send(*val).unwrap(); tx.send(*val).unwrap();
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(1));
} }
@ -39,7 +39,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
thread::spawn(move || { thread::spawn(move || {
for val in &qc2.second_half { for val in &qc2.second_half {
println!("sending {:?}", val); println!("sending {val:?}");
tx.send(*val).unwrap(); tx.send(*val).unwrap();
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(1));
} }
@ -55,10 +55,10 @@ fn main() {
let mut total_received: u32 = 0; let mut total_received: u32 = 0;
for received in rx { for received in rx {
println!("Got: {}", received); println!("Got: {received}");
total_received += 1; total_received += 1;
} }
println!("total numbers received: {}", total_received); println!("total numbers received: {total_received:?}");
assert_eq!(total_received, queue_length) assert_eq!(total_received, queue_length)
} }

View File

@ -22,7 +22,7 @@ impl AppendBar for String {
fn main() { fn main() {
let s = String::from("Foo"); let s = String::from("Foo");
let s = s.append_bar(); let s = s.append_bar();
println!("s: {}", s); println!("s: {s}");
} }
#[cfg(test)] #[cfg(test)]

View File

@ -6,5 +6,5 @@
fn main() { fn main() {
x = 5; x = 5;
println!("x has the value {}", x); println!("x has the value {x}");
} }

View File

@ -5,5 +5,5 @@
fn main() { fn main() {
let x: i32; let x: i32;
println!("Number {}", x); println!("Number {x}");
} }

View File

@ -5,7 +5,7 @@
fn main() { fn main() {
let x = 3; let x = 3;
println!("Number {}", x); println!("Number {x}");
x = 5; // don't change this line x = 5; // don't change this line
println!("Number {}", x); println!("Number {x}");
} }

View File

@ -5,7 +5,7 @@
fn main() { fn main() {
let number = "T-H-R-E-E"; // don't change this line 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 number = 3; // don't rename this variable
println!("Number plus two is : {}", number + 2); println!("Number plus two is : {}", number + 2);
} }

View File

@ -5,5 +5,5 @@
const NUMBER = 3; const NUMBER = 3;
fn main() { fn main() {
println!("Number {}", NUMBER); println!("Number {NUMBER}");
} }