From b16bb4e62cf5deed4d88101eca9b071af3c82f65 Mon Sep 17 00:00:00 2001 From: Steve Wooster Date: Sat, 26 Feb 2022 13:01:28 -0800 Subject: [PATCH] Appease clippy (#591) * Simplify .map().flatten().next() and .filter_map().next() to .find_map() * Avoid unnecessary closures for cheap expressions * Use character instead of string for replacement pattern Co-authored-by: Steve Wooster --- examples/src/lib.rs | 7 ++----- generator/src/lib.rs | 13 +++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index f7e9d2d..7140747 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -275,12 +275,12 @@ impl ExampleBase { let surface_loader = Surface::new(&entry, &instance); let (pdevice, queue_family_index) = pdevices .iter() - .map(|pdevice| { + .find_map(|pdevice| { instance .get_physical_device_queue_family_properties(*pdevice) .iter() .enumerate() - .filter_map(|(index, info)| { + .find_map(|(index, info)| { let supports_graphic_and_surface = info.queue_flags.contains(vk::QueueFlags::GRAPHICS) && surface_loader @@ -296,10 +296,7 @@ impl ExampleBase { None } }) - .next() }) - .flatten() - .next() .expect("Couldn't find suitable device."); let queue_family_index = queue_family_index as u32; let device_extension_names_raw = [Swapchain::name().as_ptr()]; diff --git a/generator/src/lib.rs b/generator/src/lib.rs index d703e3f..17930ca 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -396,7 +396,7 @@ impl FeatureExt for vkxml::Feature { version = format!("{}_0", version) } - version.replace(".", "_") + version.replace('.', "_") } } #[derive(Debug, Copy, Clone)] @@ -655,7 +655,7 @@ impl FieldExt for vkxml::Field { let size = self .size .as_ref() - .or_else(|| self.size_enumref.as_ref()) + .or(self.size_enumref.as_ref()) .expect("Should have size"); // Make sure we also rename the constant, that is // used inside the static array @@ -1207,9 +1207,7 @@ pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident { .unwrap_or(""); let struct_name = struct_name.strip_suffix(vendor).unwrap(); let struct_name = TRAILING_NUMBER.replace(struct_name, "_$1"); - let variant_name = variant_name - .strip_suffix(vendor) - .unwrap_or_else(|| variant_name.as_str()); + let variant_name = variant_name.strip_suffix(vendor).unwrap_or(&variant_name); let new_variant_name = variant_name .strip_prefix(struct_name.as_ref()) @@ -1599,7 +1597,7 @@ pub fn derive_setters( let param_ident_short = param_ident_string .strip_prefix("p_") .or_else(|| param_ident_string.strip_prefix("pp_")) - .unwrap_or_else(|| param_ident_string.as_str()); + .unwrap_or(¶m_ident_string); let param_ident_short = format_ident!("{}", ¶m_ident_short); if let Some(name) = field.name.as_ref() { @@ -2401,11 +2399,10 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { let extensions: &Vec = spec2 .0 .iter() - .filter_map(|item| match item { + .find_map(|item| match item { vk_parse::RegistryChild::Extensions(ref ext) => Some(&ext.children), _ => None, }) - .next() .expect("extension"); let mut ty_cache = HashSet::new(); let aliases: Vec<_> = spec2