diff --git a/rustfmt.toml b/rustfmt.toml index 131d9d6bc4f..9c257d0ca02 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,5 +4,6 @@ wrap_comments = true # The code blocks get a scrollbar if they are wider than this. max_width = 85 + # Allow all constructs to take up max_width columns. use_small_heuristics = "Max" diff --git a/src/android/aidl/birthday_service/src/client.rs b/src/android/aidl/birthday_service/src/client.rs index 261fcb61405..a24741a4a27 100644 --- a/src/android/aidl/birthday_service/src/client.rs +++ b/src/android/aidl/birthday_service/src/client.rs @@ -13,11 +13,13 @@ // limitations under the License. //! Birthday service. -use com_example_birthdayservice::aidl::com::example::birthdayservice::BirthdayInfo::BirthdayInfo; -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayInfoProvider::{ - BnBirthdayInfoProvider, IBirthdayInfoProvider, +use com_example_birthdayservice::aidl::com::example::birthdayservice::{ + BirthdayInfo::BirthdayInfo, + IBirthdayInfoProvider::{ + BnBirthdayInfoProvider, IBirthdayInfoProvider, + }, + IBirthdayService::IBirthdayService }; -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService; use com_example_birthdayservice::binder::{self, BinderFeatures, ParcelFileDescriptor}; use std::error::Error; use std::fs::File; diff --git a/src/android/aidl/birthday_service/src/lib.rs b/src/android/aidl/birthday_service/src/lib.rs index 1a6e5f32bf2..8ff6ef1e667 100644 --- a/src/android/aidl/birthday_service/src/lib.rs +++ b/src/android/aidl/birthday_service/src/lib.rs @@ -13,9 +13,11 @@ // limitations under the License. //! Implementation of the `IBirthdayService` AIDL interface. -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayInfoProvider::IBirthdayInfoProvider; -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService; -use com_example_birthdayservice::aidl::com::example::birthdayservice::BirthdayInfo::BirthdayInfo; +use com_example_birthdayservice::aidl::com::example::birthdayservice::{ + IBirthdayInfoProvider::IBirthdayInfoProvider, + IBirthdayService::IBirthdayService, + BirthdayInfo::BirthdayInfo +}; use com_example_birthdayservice::binder::{self, ParcelFileDescriptor, SpIBinder, Strong}; use std::fs::File; use std::io::Read; diff --git a/src/android/aidl/birthday_service/src/server.rs b/src/android/aidl/birthday_service/src/server.rs index 8393c63f35a..d1adc50d0e6 100644 --- a/src/android/aidl/birthday_service/src/server.rs +++ b/src/android/aidl/birthday_service/src/server.rs @@ -15,7 +15,9 @@ // ANCHOR: main //! Birthday service. use birthdayservice::BirthdayService; -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::BnBirthdayService; +use com_example_birthdayservice::aidl::com::example::birthdayservice::{ + IBirthdayService::BnBirthdayService +}; use com_example_birthdayservice::binder; const SERVICE_IDENTIFIER: &str = "birthdayservice"; diff --git a/src/android/aidl/example-service/client.md b/src/android/aidl/example-service/client.md index 4213496d7cf..af4a68464f5 100644 --- a/src/android/aidl/example-service/client.md +++ b/src/android/aidl/example-service/client.md @@ -5,7 +5,9 @@ Finally, we can create a Rust client for our new service. _birthday_service/src/client.rs_: ```rust,ignore -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService; +use com_example_birthdayservice::aidl::com::example::birthdayservice::{ + IBirthdayService::IBirthdayService +}; use com_example_birthdayservice::binder; {{#include ../birthday_service/src/client.rs:main}} diff --git a/src/android/aidl/example-service/service.md b/src/android/aidl/example-service/service.md index d9b1c8f8b4e..aea6321781d 100644 --- a/src/android/aidl/example-service/service.md +++ b/src/android/aidl/example-service/service.md @@ -5,7 +5,9 @@ We can now implement the AIDL service: _birthday_service/src/lib.rs_: ```rust,ignore -use com_example_birthdayservice::aidl::com::example::birthdayservice::IBirthdayService::IBirthdayService; +use com_example_birthdayservice::aidl::com::example::birthdayservice::{ + IBirthdayService::IBirthdayService +}; use com_example_birthdayservice::binder; {{#include ../birthday_service/src/lib.rs:IBirthdayService}} diff --git a/src/bare-metal/microcontrollers/examples/src/bin/typestate.rs b/src/bare-metal/microcontrollers/examples/src/bin/typestate.rs index 71071aff700..8eda33d9773 100644 --- a/src/bare-metal/microcontrollers/examples/src/bin/typestate.rs +++ b/src/bare-metal/microcontrollers/examples/src/bin/typestate.rs @@ -40,13 +40,17 @@ fn main() -> ! { // ... } let mut pin_output: P0_01> = pin_input - .into_open_drain_output(OpenDrainConfig::Disconnect0Standard1, Level::Low); + .into_open_drain_output( + OpenDrainConfig::Disconnect0Standard1, + Level::Low, + ); pin_output.set_high().unwrap(); // pin_input.is_high(); // Error, moved. - let _pin2: P0_02> = gpio0 - .p0_02 - .into_open_drain_output(OpenDrainConfig::Disconnect0Standard1, Level::Low); + let _pin2: P0_02> = gpio0.p0_02.into_open_drain_output( + OpenDrainConfig::Disconnect0Standard1, + Level::Low, + ); let _pin3: P0_03> = gpio0.p0_03.into_push_pull_output(Level::Low); diff --git a/src/borrowing/exercise.md b/src/borrowing/exercise.md index a6b9cd3a2e8..160aa9f43cf 100644 --- a/src/borrowing/exercise.md +++ b/src/borrowing/exercise.md @@ -16,7 +16,10 @@ method: {{#include ../../third_party/rust-on-exercism/health-statistics.rs:setup}} {{#include ../../third_party/rust-on-exercism/health-statistics.rs:User_visit_doctor}} - todo!("Update a user's statistics based on measurements from a visit to the doctor") + todo!( + "Update a user's statistics based on measurements from a visit to \ + the doctor" + ) } } diff --git a/src/error-handling/exercise.rs b/src/error-handling/exercise.rs index 6b4511112d8..3a052ad3a3b 100644 --- a/src/error-handling/exercise.rs +++ b/src/error-handling/exercise.rs @@ -73,7 +73,8 @@ impl<'a> Iterator for Tokenizer<'a> { } 'a'..='z' => { let mut ident = String::from(c); - while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() { + while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() + { ident.push(*c); self.0.next(); } @@ -160,7 +161,8 @@ impl<'a> Iterator for Tokenizer<'a> { } 'a'..='z' => { let mut ident = String::from(c); - while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() { + while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() + { ident.push(*c); self.0.next(); } diff --git a/src/iterators/intoiterator.md b/src/iterators/intoiterator.md index aeb22c243d1..afc76b8f614 100644 --- a/src/iterators/intoiterator.md +++ b/src/iterators/intoiterator.md @@ -48,7 +48,8 @@ impl Iterator for GridIter { } fn main() { - let grid = Grid { x_coords: vec![3, 5, 7, 9], y_coords: vec![10, 20, 30, 40] }; + let grid = + Grid { x_coords: vec![3, 5, 7, 9], y_coords: vec![10, 20, 30, 40] }; for (x, y) in grid { println!("point = {x}, {y}"); } diff --git a/src/lifetimes/exercise.md b/src/lifetimes/exercise.md index c742abf9a59..c34c15d715b 100644 --- a/src/lifetimes/exercise.md +++ b/src/lifetimes/exercise.md @@ -49,7 +49,10 @@ What remains for you is to implement the `parse_field` function and the {{#include exercise.rs:parse_field }} - _ => todo!("Based on the wire type, build a Field, consuming as many bytes as necessary.") + _ => todo!( + "Based on the wire type, build a Field, consuming as many bytes as \ + necessary." + ) }; todo!("Return the field, and any un-consumed bytes.") } diff --git a/src/lifetimes/exercise.rs b/src/lifetimes/exercise.rs index ab73d9ce1cd..b06d1e3c95b 100644 --- a/src/lifetimes/exercise.rs +++ b/src/lifetimes/exercise.rs @@ -170,7 +170,9 @@ fn parse_field(data: &[u8]) -> Result<(Field, &[u8]), Error> { /// the message. /// /// The entire input is consumed. -fn parse_message<'a, T: ProtoMessage<'a>>(mut data: &'a [u8]) -> Result { +fn parse_message<'a, T: ProtoMessage<'a>>( + mut data: &'a [u8], +) -> Result { let mut result = T::default(); while !data.is_empty() { let parsed = parse_field(data)?; diff --git a/src/memory-management/exercise.rs b/src/memory-management/exercise.rs index 44251c5040b..e5d536f0f8c 100644 --- a/src/memory-management/exercise.rs +++ b/src/memory-management/exercise.rs @@ -114,8 +114,10 @@ impl PackageBuilder { fn main() { let base64 = PackageBuilder::new("base64").version("0.13").build(); println!("base64: {base64:?}"); - let log = - PackageBuilder::new("log").version("0.4").language(Language::Rust).build(); + let log = PackageBuilder::new("log") + .version("0.4") + .language(Language::Rust) + .build(); println!("log: {log:?}"); let serde = PackageBuilder::new("serde") .authors(vec!["djmitche".into()]) diff --git a/src/memory-management/review.md b/src/memory-management/review.md index 04c719a8dbf..6e47d45d0cd 100644 --- a/src/memory-management/review.md +++ b/src/memory-management/review.md @@ -65,7 +65,8 @@ fn main() { // String provides no guarantees about its layout, so this could lead to // undefined behavior. unsafe { - let (capacity, ptr, len): (usize, usize, usize) = std::mem::transmute(s1); + let (capacity, ptr, len): (usize, usize, usize) = + std::mem::transmute(s1); println!("capacity = {capacity}, ptr = {ptr:#x}, len = {len}"); } } diff --git a/src/testing/exercise.rs b/src/testing/exercise.rs index 385eb9bd430..24d92505758 100644 --- a/src/testing/exercise.rs +++ b/src/testing/exercise.rs @@ -24,8 +24,11 @@ pub fn luhn(cc_number: &str) -> bool { if let Some(digit) = c.to_digit(10) { if double { let double_digit = digit * 2; - sum += - if double_digit > 9 { double_digit - 9 } else { double_digit }; + sum += if double_digit > 9 { + double_digit - 9 + } else { + double_digit + }; } else { sum += digit; } @@ -50,8 +53,11 @@ pub fn luhn(cc_number: &str) -> bool { digits += 1; if double { let double_digit = digit * 2; - sum += - if double_digit > 9 { double_digit - 9 } else { double_digit }; + sum += if double_digit > 9 { + double_digit - 9 + } else { + double_digit + }; } else { sum += digit; } diff --git a/src/unsafe-rust/exercise.rs b/src/unsafe-rust/exercise.rs index 0eb0cc6c775..d0a91c7f88d 100644 --- a/src/unsafe-rust/exercise.rs +++ b/src/unsafe-rust/exercise.rs @@ -23,7 +23,8 @@ mod ffi { #[repr(C)] pub struct DIR { _data: [u8; 0], - _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, + _marker: + core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, } // Layout according to the Linux man page for readdir(3), where ino_t and diff --git a/src/unsafe-rust/unsafe-functions.md b/src/unsafe-rust/unsafe-functions.md index 6503506f8fc..81ac46a6898 100644 --- a/src/unsafe-rust/unsafe-functions.md +++ b/src/unsafe-rust/unsafe-functions.md @@ -25,7 +25,9 @@ fn main() { println!("emoji: {}", emojis.get_unchecked(7..11)); } - println!("char count: {}", count_chars(unsafe { emojis.get_unchecked(0..7) })); + println!( + "char count: {}", + count_chars(unsafe { emojis.get_unchecked(0..7) })); // SAFETY: `abs` doesn't deal with pointers and doesn't have any safety // requirements. diff --git a/src/user-defined-types/enums.md b/src/user-defined-types/enums.md index dc34b80ffbf..fefbaa6d1fc 100644 --- a/src/user-defined-types/enums.md +++ b/src/user-defined-types/enums.md @@ -88,7 +88,11 @@ Rust has several optimizations it can employ to make enums take up less space. macro_rules! dbg_bits { ($e:expr, $bit_type:ty) => { - println!("- {}: {:#x}", stringify!($e), transmute::<_, $bit_type>($e)); + println!( + "- {}: {:#x}", + stringify!($e), + transmute::<_, $bit_type>($e) + ); }; } diff --git a/third_party/rust-on-exercism/health-statistics.rs b/third_party/rust-on-exercism/health-statistics.rs index 52ab7ebb72e..d0f3b0e008f 100644 --- a/third_party/rust-on-exercism/health-statistics.rs +++ b/third_party/rust-on-exercism/health-statistics.rs @@ -38,9 +38,10 @@ impl User { visit_count: self.visit_count as u32, height_change: measurements.height - self.height, blood_pressure_change: match self.last_blood_pressure { - Some(lbp) => { - Some((bp.0 as i32 - lbp.0 as i32, bp.1 as i32 - lbp.1 as i32)) - } + Some(lbp) => Some(( + bp.0 as i32 - lbp.0 as i32, + bp.1 as i32 - lbp.1 as i32, + )), None => None, }, }; @@ -62,14 +63,14 @@ fn main() { fn test_visit() { let mut bob = User::new(String::from("Bob"), 32, 155.2); assert_eq!(bob.visit_count, 0); - let report = - bob.visit_doctor(Measurements { height: 156.1, blood_pressure: (120, 80) }); + let report = bob + .visit_doctor(Measurements { height: 156.1, blood_pressure: (120, 80) }); assert_eq!(report.patient_name, "Bob"); assert_eq!(report.visit_count, 1); assert_eq!(report.blood_pressure_change, None); - let report = - bob.visit_doctor(Measurements { height: 156.1, blood_pressure: (115, 76) }); + let report = bob + .visit_doctor(Measurements { height: 156.1, blood_pressure: (115, 76) }); assert_eq!(report.visit_count, 2); assert_eq!(report.blood_pressure_change, Some((-5, -4)));