From 8239d2ff84b8b975b968d16065850f35d08513c4 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 30 Jun 2022 21:15:35 -0400 Subject: [PATCH] Use named args in format (requires 1.58) See https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html --- .appveyor.yml | 2 +- README.md | 4 ++-- build.rs | 2 +- examples/count.rs | 8 ++++---- examples/indexed.rs | 2 +- src/elements.rs | 6 +++--- src/error.rs | 10 +++++----- src/indexed.rs | 4 ++-- src/lib.rs | 4 ++-- src/reader.rs | 4 ++-- tests/read.rs | 6 ++---- 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 5416312..2ef062c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,7 +16,7 @@ environment: target: x86_64-pc-windows-msvc - channel: stable target: i686-pc-windows-msvc - - channel: 1.52.1 + - channel: 1.58.0 target: x86_64-pc-windows-msvc install: diff --git a/README.md b/README.md index ee8a18d..0bb41e1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ reader.for_each(|element| { } })?; -println!("Number of ways: {}", ways); +println!("Number of ways: {ways}"); ``` In this second example, we also count the ways but make use of all cores by @@ -57,7 +57,7 @@ let ways = reader.par_map_reduce( |a, b| a + b // Sum the partial results )?; -println!("Number of ways: {}", ways); +println!("Number of ways: {ways}"); ``` ## The PBF format diff --git a/build.rs b/build.rs index 861e4b0..140952a 100644 --- a/build.rs +++ b/build.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), Box> { let proto_files = ["src/proto/fileformat.proto", "src/proto/osmformat.proto"]; for path in &proto_files { - println!("cargo:rerun-if-changed={}", path); + println!("cargo:rerun-if-changed={path}"); } let out_dir = std::env::var("OUT_DIR")?; diff --git a/examples/count.rs b/examples/count.rs index ddba332..2684725 100644 --- a/examples/count.rs +++ b/examples/count.rs @@ -22,12 +22,12 @@ fn main() { |a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2), ) { Ok((nodes, ways, relations)) => { - println!("Nodes: {}", nodes); - println!("Ways: {}", ways); - println!("Relations: {}", relations); + println!("Nodes: {nodes}"); + println!("Ways: {ways}"); + println!("Relations: {relations}"); } Err(e) => { - println!("{}", e); + println!("{e}"); } } } diff --git a/examples/indexed.rs b/examples/indexed.rs index 7507aad..4d07437 100644 --- a/examples/indexed.rs +++ b/examples/indexed.rs @@ -32,6 +32,6 @@ fn main() -> Result<(), Box> { )?; // Print result - println!("ways: {}\nnodes: {}", ways, nodes); + println!("ways: {ways}\nnodes: {nodes}"); Ok(()) } diff --git a/src/elements.rs b/src/elements.rs index 8708a59..08fa561 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -56,7 +56,7 @@ impl<'a> Node<'a> { /// reader.for_each(|element| { /// if let Element::Node(node) = element { /// for (key, value) in node.tags() { - /// println!("key: {}, value: {}", key, value); + /// println!("key: {key}, value: {value}"); /// } /// } /// })?; @@ -164,7 +164,7 @@ impl<'a> Way<'a> { /// reader.for_each(|element| { /// if let Element::Way(way) = element { /// for (key, value) in way.tags() { - /// println!("key: {}, value: {}", key, value); + /// println!("key: {key}, value: {value}"); /// } /// } /// })?; @@ -273,7 +273,7 @@ impl<'a> Relation<'a> { /// reader.for_each(|element| { /// if let Element::Relation(relation) = element { /// for (key, value) in relation.tags() { - /// println!("key: {}, value: {}", key, value); + /// println!("key: {key}, value: {value}"); /// } /// } /// })?; diff --git a/src/error.rs b/src/error.rs index 9d9882f..81a3490 100644 --- a/src/error.rs +++ b/src/error.rs @@ -151,22 +151,22 @@ impl fmt::Display for Error { match *self.0 { ErrorKind::Io(ref err) => err.fmt(f), ErrorKind::Protobuf { ref err, location } => { - write!(f, "protobuf error at '{}': {}", location, err) + write!(f, "protobuf error at '{location}': {err}") } ErrorKind::StringtableUtf8 { ref err, index } => { - write!(f, "invalid UTF-8 at string table index {}: {}", index, err) + write!(f, "invalid UTF-8 at string table index {index}: {err}") } ErrorKind::StringtableIndexOutOfBounds { index } => { - write!(f, "stringtable index out of bounds: {}", index) + write!(f, "stringtable index out of bounds: {index}") } ErrorKind::Blob(BlobError::InvalidHeaderSize) => { write!(f, "blob header size could not be decoded") } ErrorKind::Blob(BlobError::HeaderTooBig { size }) => { - write!(f, "blob header is too big: {} bytes", size) + write!(f, "blob header is too big: {size} bytes") } ErrorKind::Blob(BlobError::MessageTooBig { size }) => { - write!(f, "blob message is too big: {} bytes", size) + write!(f, "blob message is too big: {size} bytes") } ErrorKind::Blob(BlobError::Empty) => { write!(f, "blob is missing fields 'raw' and 'zlib_data'") diff --git a/src/indexed.rs b/src/indexed.rs index e315383..8168326 100644 --- a/src/indexed.rs +++ b/src/indexed.rs @@ -253,7 +253,7 @@ impl IndexedReader { /// }, /// )?; /// - /// println!("ways: {}\nnodes: {}", ways, nodes); + /// println!("ways: {ways}\nnodes: {nodes}"); /// /// # assert_eq!(ways, 1); /// # assert_eq!(nodes, 3); @@ -354,7 +354,7 @@ impl IndexedReader { /// }, /// )?; /// - /// println!("nodes: {}", nodes); + /// println!("nodes: {nodes}"); /// /// # assert_eq!(nodes, 3); /// # Ok(()) diff --git a/src/lib.rs b/src/lib.rs index a0b09fe..ee71945 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ reader.for_each(|element| { } })?; -println!("Number of ways: {}", ways); +println!("Number of ways: {ways}"); # assert_eq!(ways, 1); # Ok::<(), std::io::Error>(()) ``` @@ -55,7 +55,7 @@ let ways = reader.par_map_reduce( |a, b| a + b // Sum the partial results )?; -println!("Number of ways: {}", ways); +println!("Number of ways: {ways}"); # assert_eq!(ways, 1); # Ok::<(), std::io::Error>(()) ``` diff --git a/src/reader.rs b/src/reader.rs index bfea8a8..40069dd 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -58,7 +58,7 @@ impl ElementReader { /// } /// })?; /// - /// println!("Number of ways: {}", ways); + /// println!("Number of ways: {ways}"); /// /// # Ok(()) /// # } @@ -111,7 +111,7 @@ impl ElementReader { /// |a, b| a + b // Sum the partial results /// )?; /// - /// println!("Number of ways: {}", ways); + /// println!("Number of ways: {ways}"); /// # Ok(()) /// # } /// # foo().unwrap(); diff --git a/tests/read.rs b/tests/read.rs index 15b7e30..879c76e 100644 --- a/tests/read.rs +++ b/tests/read.rs @@ -90,15 +90,13 @@ fn check_header_block_content(block: &HeaderBlock, test_file: &TestFile) { let res = block.required_features(); assert!( is_same_unordered(test_file.req, res), - "Required features {:?} don't match expected {:?}", - res, + "Required features {res:?} don't match expected {:?}", test_file.req ); let res = block.optional_features(); assert!( is_same_unordered(test_file.opt, res), - "Optional features {:?} don't match expected {:?}", - res, + "Optional features {res:?} don't match expected {:?}", test_file.opt ); }