diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..72864b6 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,10 @@ +# We don't actually want rustfmt to do all the formatting, as there isn't enough granularity. +# Therefore, any options that follow this one are symbolic as guidelines, rather than rules +# for rustfmt. +#disable_all_formatting = true + +brace_style = "AlwaysNextLine" +control_brace_style = "AlwaysSameLine" +binop_separator = "Back" +match_block_trailing_comma = true +overflow_delimited_expr = true diff --git a/src/error.rs b/src/error.rs index 6df476f..01bea88 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,8 @@ use thiserror::Error; pub enum BmputilError { #[error("Access denied when attempting to {operation} to {context}")] - PermissionsError { + PermissionsError + { #[source] source: rusb::Error, @@ -19,7 +20,8 @@ pub enum BmputilError }, #[error("Blackmagic Probe device found disconnected when attempting to {operation} to {context}")] - DeviceDisconnectDuringOperationError { + DeviceDisconnectDuringOperationError + { #[source] source: rusb::Error, @@ -32,7 +34,8 @@ pub enum BmputilError #[allow(dead_code)] // FIXME: this will presumably be used once we have more dynamic detection of re-enumeration. #[error("Blackmagic Probe device did not re-enumerate after requesting to switch to DFU mode")] - DeviceReconfigureError { + DeviceReconfigureError + { /// Source is optional because there may be no libusb error, if detecting connection is /// done through e.g. checking device lists. #[source] @@ -41,7 +44,8 @@ pub enum BmputilError #[allow(dead_code)] // FIXME: this will presumably be used once we, well, actually implement the post-flash check. #[error("Blackmagic Probe device did not re-enumerate after flashing firmware; firmware may be invalid?")] - DeviceRebootError { + DeviceRebootError + { #[source] source: Option, }, @@ -51,7 +55,8 @@ pub enum BmputilError "Blackmagic Probe device returned bad data ({invalid_thing}) during configuration.\ This generally shouldn't be possible. Maybe cable is bad, or OS is messing with things?" )] - DeviceSeemsInvalidError { + DeviceSeemsInvalidError + { #[source] source: Option, invalid_thing: String, @@ -63,7 +68,8 @@ pub enum BmputilError #[macro_export] -macro_rules! log_and_return { +macro_rules! log_and_return +{ ($err:expr) => { let err = $err; log::error!("{}", err); diff --git a/src/main.rs b/src/main.rs index 1808116..55619a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,8 @@ type DfuDevice = DfuSync, DfuLibusbError>; fn device_matches_vid_pid(device: &rusb::Device, vid: Vid, pid: Pid) -> bool - where ContextT: UsbContext, +where + ContextT: UsbContext, { let dev_descriptor = device.device_descriptor() .expect(libusb_cannot_fail!("libusb_get_device_descriptor()")); @@ -58,8 +59,6 @@ fn detach_device(device: rusb::Device) -> Result<(), BmputilError // USB configuration descriptors are 1-indexed, as 0 is considered // to be "unconfigured". - //device.config_descriptor(1) - //.expect("Device seems to not have any configuration descriptors! This shouldn't be possible!") match device.config_descriptor(1) { Ok(d) => d, Err(e) => { @@ -76,10 +75,14 @@ fn detach_device(device: rusb::Device) -> Result<(), BmputilError }; // Get the descriptor for the DFU interface on the Blackmagic Probe. - let dfu_interface_descriptor = configuration.interfaces() - .map(|interface| interface.descriptors() - .next().unwrap() // Unwrap fine as we've already established there is at least one interface. - ) + let dfu_interface_descriptor = configuration + .interfaces() + .map(|interface| { + interface + .descriptors() + .next() + .unwrap() // Unwrap fine as we've already established there is at least one interface. + }) .find(interface_descriptor_is_dfu) .ok_or_else(|| BmputilError::DeviceSeemsInvalidError { source: None, diff --git a/src/usb.rs b/src/usb.rs index 4b7196b..df510b3 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -138,7 +138,8 @@ pub enum DescriptorConvertError "bLength field ({provided_length}) in provided data does not match the correct value\ ({correct_length}) for this descriptor type" )] - LengthFieldMismatch { + LengthFieldMismatch + { provided_length: u8, correct_length: u8, }, @@ -147,7 +148,8 @@ pub enum DescriptorConvertError "bDescriptorType field ({provided_type}) in provided data does not match the correct\ value ({correct_type}) for this descriptor type" )] - DescriptorTypeMismatch { + DescriptorTypeMismatch + { provided_type: u8, correct_type: u8, }, @@ -221,9 +223,11 @@ pub(crate) const CHECKED_LIBUSB_VERSION: &str = "1.0.26"; macro_rules! libusb_cannot_fail { ($funcname:literal) => { - format!("As of libusb {}, {} cannot fail. This should be unreachable, unless libusb has updated.", + format!( + "As of libusb {}, {} cannot fail. This should be unreachable, unless libusb has updated.", crate::usb::CHECKED_LIBUSB_VERSION, $funcname, - ).as_str() - } + ) + .as_str() + }; }