From b71dc58efbbadb5d27f377fcd9246e2529a34541 Mon Sep 17 00:00:00 2001 From: Matus Talcik Date: Sat, 17 Nov 2018 19:05:28 +0100 Subject: [PATCH] Initial support for rustfmt --- .travis.yml | 5 + ash/src/device.rs | 55 +++------- ash/src/entry.rs | 20 ++-- ash/src/extensions/android_surface.rs | 5 +- ash/src/extensions/debug_marker.rs | 5 +- ash/src/extensions/debug_report.rs | 5 +- ash/src/extensions/debug_utils.rs | 13 +-- ash/src/extensions/display_swapchain.rs | 5 +- ash/src/extensions/ios_surface.rs | 5 +- ash/src/extensions/macos_surface.rs | 5 +- ash/src/extensions/surface.rs | 5 +- ash/src/extensions/swapchain.rs | 5 +- ash/src/extensions/wayland_surface.rs | 5 +- ash/src/extensions/win32_surface.rs | 5 +- ash/src/extensions/xcb_surface.rs | 5 +- ash/src/extensions/xlib_surface.rs | 5 +- ash/src/util.rs | 6 +- ash/tests/display.rs | 6 +- examples/src/bin/texture.rs | 73 ++++++------- examples/src/bin/triangle.rs | 34 +++--- examples/src/lib.rs | 44 ++++---- generator/src/lib.rs | 133 +++++++++++------------- rustfmt.toml | 3 +- 23 files changed, 177 insertions(+), 275 deletions(-) diff --git a/.travis.yml b/.travis.yml index 026b395..2169ccd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,17 @@ os: - linux - osx + language: rust +before_script: +- rustup component add rustfmt-preview + rust: - stable script: + - cargo fmt --all -- --check - cargo build --manifest-path ash/Cargo.toml - cargo build --manifest-path examples/Cargo.toml - cargo build --manifest-path generator/Cargo.toml diff --git a/ash/src/device.rs b/ash/src/device.rs index 8623be2..4c4330d 100644 --- a/ash/src/device.rs +++ b/ash/src/device.rs @@ -51,11 +51,7 @@ pub trait DeviceV1_1: DeviceV1_0 { peer_memory_features } - unsafe fn cmd_set_device_mask( - &self, - command_buffer: vk::CommandBuffer, - device_mask: u32, - ) { + unsafe fn cmd_set_device_mask(&self, command_buffer: vk::CommandBuffer, device_mask: u32) { self.fp_v1_1() .cmd_set_device_mask(command_buffer, device_mask); } @@ -86,11 +82,8 @@ pub trait DeviceV1_1: DeviceV1_0 { info: &vk::ImageMemoryRequirementsInfo2, out: &mut vk::MemoryRequirements2, ) { - self.fp_v1_1().get_image_memory_requirements2( - self.handle(), - info, - out, - ); + self.fp_v1_1() + .get_image_memory_requirements2(self.handle(), info, out); } unsafe fn get_buffer_memory_requirements2( @@ -98,11 +91,8 @@ pub trait DeviceV1_1: DeviceV1_0 { info: &vk::BufferMemoryRequirementsInfo2, out: &mut vk::MemoryRequirements2, ) { - self.fp_v1_1().get_buffer_memory_requirements2( - self.handle(), - info, - out, - ); + self.fp_v1_1() + .get_buffer_memory_requirements2(self.handle(), info, out); } unsafe fn get_image_sparse_memory_requirements2_len( @@ -221,11 +211,8 @@ pub trait DeviceV1_1: DeviceV1_0 { create_info: &vk::DescriptorSetLayoutCreateInfo, out: &mut vk::DescriptorSetLayoutSupport, ) { - self.fp_v1_1().get_descriptor_set_layout_support( - self.handle(), - create_info, - out, - ); + self.fp_v1_1() + .get_descriptor_set_layout_support(self.handle(), create_info, out); } } @@ -721,11 +708,9 @@ pub trait DeviceV1_0 { } unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> { - let err_code = self.fp_v1_0().reset_fences( - self.handle(), - fences.len() as u32, - fences.as_ptr(), - ); + let err_code = + self.fp_v1_0() + .reset_fences(self.handle(), fences.len() as u32, fences.as_ptr()); match err_code { vk::Result::SUCCESS => Ok(()), _ => Err(err_code), @@ -1357,11 +1342,7 @@ pub trait DeviceV1_0 { } } - unsafe fn get_device_queue( - &self, - queue_family_index: u32, - queue_index: u32, - ) -> vk::Queue { + unsafe fn get_device_queue(&self, queue_family_index: u32, queue_index: u32) -> vk::Queue { let mut queue = mem::uninitialized(); self.fp_v1_0() .get_device_queue(self.handle(), queue_family_index, queue_index, &mut queue); @@ -1473,12 +1454,9 @@ pub trait DeviceV1_0 { submits: &[vk::SubmitInfo], fence: vk::Fence, ) -> VkResult<()> { - let err_code = self.fp_v1_0().queue_submit( - queue, - submits.len() as u32, - submits.as_ptr(), - fence, - ); + let err_code = + self.fp_v1_0() + .queue_submit(queue, submits.len() as u32, submits.as_ptr(), fence); match err_code { vk::Result::SUCCESS => Ok(()), _ => Err(err_code), @@ -1725,10 +1703,7 @@ pub struct Device { device_fn_1_1: vk::DeviceFnV1_1, } impl Device { - pub unsafe fn load( - instance_fn: &vk::InstanceFnV1_0, - device: vk::Device, - ) -> Self { + pub unsafe fn load(instance_fn: &vk::InstanceFnV1_0, device: vk::Device) -> Self { let device_fn_1_0 = vk::DeviceFnV1_0::load(|name| { mem::transmute(instance_fn.get_device_proc_addr(device, name.as_ptr())) }); diff --git a/ash/src/entry.rs b/ash/src/entry.rs index 6c8a7b1..643c972 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -15,18 +15,14 @@ use RawPtr; #[cfg(windows)] const LIB_PATH: &'static str = "vulkan-1.dll"; -#[cfg( - all( - unix, - not( - any( - target_os = "macos", - target_os = "ios", - target_os = "android" - ) - ) - ) -)] +#[cfg(all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "android" + )) +))] const LIB_PATH: &'static str = "libvulkan.so.1"; #[cfg(target_os = "android")] diff --git a/ash/src/extensions/android_surface.rs b/ash/src/extensions/android_surface.rs index 5a38e59..9643d6b 100644 --- a/ash/src/extensions/android_surface.rs +++ b/ash/src/extensions/android_surface.rs @@ -13,10 +13,7 @@ pub struct AndroidSurface { } impl AndroidSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> AndroidSurface { + pub fn new(entry: &E, instance: &I) -> AndroidSurface { let surface_fn = vk::KhrAndroidSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/debug_marker.rs b/ash/src/extensions/debug_marker.rs index 13ec427..5483985 100644 --- a/ash/src/extensions/debug_marker.rs +++ b/ash/src/extensions/debug_marker.rs @@ -11,10 +11,7 @@ pub struct DebugMarker { } impl DebugMarker { - pub fn new( - instance: &I, - device: &D, - ) -> DebugMarker { + pub fn new(instance: &I, device: &D) -> DebugMarker { let debug_marker_fn = vk::ExtDebugMarkerFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/debug_report.rs b/ash/src/extensions/debug_report.rs index b819115..421b3a9 100644 --- a/ash/src/extensions/debug_report.rs +++ b/ash/src/extensions/debug_report.rs @@ -13,10 +13,7 @@ pub struct DebugReport { } impl DebugReport { - pub fn new( - entry: &E, - instance: &I, - ) -> DebugReport { + pub fn new(entry: &E, instance: &I) -> DebugReport { let debug_report_fn = vk::ExtDebugReportFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/debug_utils.rs b/ash/src/extensions/debug_utils.rs index bfdc291..67485a0 100644 --- a/ash/src/extensions/debug_utils.rs +++ b/ash/src/extensions/debug_utils.rs @@ -12,10 +12,7 @@ pub struct DebugUtils { } impl DebugUtils { - pub fn new( - entry: &E, - instance: &I, - ) -> DebugUtils { + pub fn new(entry: &E, instance: &I) -> DebugUtils { let debug_utils_fn = vk::ExtDebugUtilsFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); @@ -34,7 +31,9 @@ impl DebugUtils { device: vk::Device, name_info: &vk::DebugUtilsObjectNameInfoEXT, ) -> VkResult<()> { - let err_code = self.debug_utils_fn.set_debug_utils_object_name_ext(device, name_info); + let err_code = self + .debug_utils_fn + .set_debug_utils_object_name_ext(device, name_info); match err_code { vk::Result::SUCCESS => Ok(()), _ => Err(err_code), @@ -46,7 +45,9 @@ impl DebugUtils { device: vk::Device, tag_info: &vk::DebugUtilsObjectTagInfoEXT, ) -> VkResult<()> { - let err_code = self.debug_utils_fn.set_debug_utils_object_tag_ext(device, tag_info); + let err_code = self + .debug_utils_fn + .set_debug_utils_object_tag_ext(device, tag_info); match err_code { vk::Result::SUCCESS => Ok(()), _ => Err(err_code), diff --git a/ash/src/extensions/display_swapchain.rs b/ash/src/extensions/display_swapchain.rs index ff02aef..5cd0184 100644 --- a/ash/src/extensions/display_swapchain.rs +++ b/ash/src/extensions/display_swapchain.rs @@ -13,10 +13,7 @@ pub struct DisplaySwapchain { } impl DisplaySwapchain { - pub fn new( - instance: &I, - device: &D, - ) -> DisplaySwapchain { + pub fn new(instance: &I, device: &D) -> DisplaySwapchain { let swapchain_fn = vk::KhrDisplaySwapchainFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/ios_surface.rs b/ash/src/extensions/ios_surface.rs index 97eaad6..1d7a234 100644 --- a/ash/src/extensions/ios_surface.rs +++ b/ash/src/extensions/ios_surface.rs @@ -13,10 +13,7 @@ pub struct IOSSurface { } impl IOSSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> IOSSurface{ + pub fn new(entry: &E, instance: &I) -> IOSSurface { let surface_fn = vk::MvkIosSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/macos_surface.rs b/ash/src/extensions/macos_surface.rs index a7d26ae..8264c95 100644 --- a/ash/src/extensions/macos_surface.rs +++ b/ash/src/extensions/macos_surface.rs @@ -13,10 +13,7 @@ pub struct MacOSSurface { } impl MacOSSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> MacOSSurface { + pub fn new(entry: &E, instance: &I) -> MacOSSurface { let surface_fn = vk::MvkMacosSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/surface.rs b/ash/src/extensions/surface.rs index 16b8da4..3f37bb7 100644 --- a/ash/src/extensions/surface.rs +++ b/ash/src/extensions/surface.rs @@ -14,10 +14,7 @@ pub struct Surface { } impl Surface { - pub fn new( - entry: &E, - instance: &I, - ) -> Surface { + pub fn new(entry: &E, instance: &I) -> Surface { let surface_fn = vk::KhrSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/swapchain.rs b/ash/src/extensions/swapchain.rs index 956b5bc..5841602 100644 --- a/ash/src/extensions/swapchain.rs +++ b/ash/src/extensions/swapchain.rs @@ -14,10 +14,7 @@ pub struct Swapchain { } impl Swapchain { - pub fn new( - instance: &I, - device: &D, - ) -> Swapchain { + pub fn new(instance: &I, device: &D) -> Swapchain { let swapchain_fn = vk::KhrSwapchainFn::load(|name| unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/wayland_surface.rs b/ash/src/extensions/wayland_surface.rs index 482f27d..04cdd2f 100644 --- a/ash/src/extensions/wayland_surface.rs +++ b/ash/src/extensions/wayland_surface.rs @@ -13,10 +13,7 @@ pub struct WaylandSurface { } impl WaylandSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> WaylandSurface { + pub fn new(entry: &E, instance: &I) -> WaylandSurface { let surface_fn = vk::KhrWaylandSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/win32_surface.rs b/ash/src/extensions/win32_surface.rs index 5576e50..15339bd 100644 --- a/ash/src/extensions/win32_surface.rs +++ b/ash/src/extensions/win32_surface.rs @@ -13,10 +13,7 @@ pub struct Win32Surface { } impl Win32Surface { - pub fn new( - entry: &E, - instance: &I, - ) -> Win32Surface { + pub fn new(entry: &E, instance: &I) -> Win32Surface { let surface_fn = vk::KhrWin32SurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/xcb_surface.rs b/ash/src/extensions/xcb_surface.rs index 2c45c36..5575533 100644 --- a/ash/src/extensions/xcb_surface.rs +++ b/ash/src/extensions/xcb_surface.rs @@ -13,10 +13,7 @@ pub struct XcbSurface { } impl XcbSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> XcbSurface { + pub fn new(entry: &E, instance: &I) -> XcbSurface { let surface_fn = vk::KhrXcbSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/extensions/xlib_surface.rs b/ash/src/extensions/xlib_surface.rs index 34293d2..79c3990 100644 --- a/ash/src/extensions/xlib_surface.rs +++ b/ash/src/extensions/xlib_surface.rs @@ -13,10 +13,7 @@ pub struct XlibSurface { } impl XlibSurface { - pub fn new( - entry: &E, - instance: &I, - ) -> XlibSurface { + pub fn new(entry: &E, instance: &I) -> XlibSurface { let surface_fn = vk::KhrXlibSurfaceFn::load(|name| unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }); diff --git a/ash/src/util.rs b/ash/src/util.rs index 173d2da..8abd572 100644 --- a/ash/src/util.rs +++ b/ash/src/util.rs @@ -46,11 +46,7 @@ fn calc_padding(adr: vk::DeviceSize, align: vk::DeviceSize) -> vk::DeviceSize { } impl Align { - pub unsafe fn new( - ptr: *mut c_void, - alignment: vk::DeviceSize, - size: vk::DeviceSize, - ) -> Self { + pub unsafe fn new(ptr: *mut c_void, alignment: vk::DeviceSize, size: vk::DeviceSize) -> Self { let padding = calc_padding(size_of::() as vk::DeviceSize, alignment); let elem_size = size_of::() as vk::DeviceSize + padding; assert!(calc_padding(size, alignment) == 0, "size must be aligned"); diff --git a/ash/tests/display.rs b/ash/tests/display.rs index 5ab861a..7f2eb1d 100644 --- a/ash/tests/display.rs +++ b/ash/tests/display.rs @@ -3,7 +3,11 @@ use ash::vk; #[test] fn display_flags() { - assert_eq!((vk::AccessFlags::INDIRECT_COMMAND_READ | vk::AccessFlags::VERTEX_ATTRIBUTE_READ).to_string(), "INDIRECT_COMMAND_READ | VERTEX_ATTRIBUTE_READ"); + assert_eq!( + (vk::AccessFlags::INDIRECT_COMMAND_READ | vk::AccessFlags::VERTEX_ATTRIBUTE_READ) + .to_string(), + "INDIRECT_COMMAND_READ | VERTEX_ATTRIBUTE_READ" + ); } #[test] diff --git a/examples/src/bin/texture.rs b/examples/src/bin/texture.rs index 6435236..dc68c8d 100644 --- a/examples/src/bin/texture.rs +++ b/examples/src/bin/texture.rs @@ -121,8 +121,7 @@ fn main() { base.device .create_framebuffer(&frame_buffer_create_info, None) .unwrap() - }) - .collect(); + }).collect(); let index_buffer_data = [0u32, 1, 2, 2, 3, 0]; let index_buffer_info = vk::BufferCreateInfo { s_type: vk::StructureType::BUFFER_CREATE_INFO, @@ -136,12 +135,11 @@ fn main() { }; let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); - let index_buffer_memory_index = - find_memorytype_index( - &index_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the index buffer."); + let index_buffer_memory_index = find_memorytype_index( + &index_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the index buffer."); let index_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, p_next: ptr::null(), @@ -159,8 +157,7 @@ fn main() { 0, index_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut index_slice = Align::new( index_ptr, align_of::() as u64, @@ -207,12 +204,11 @@ fn main() { let vertex_input_buffer_memory_req = base .device .get_buffer_memory_requirements(vertex_input_buffer); - let vertex_input_buffer_memory_index = - find_memorytype_index( - &vertex_input_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + let vertex_input_buffer_memory_index = find_memorytype_index( + &vertex_input_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the vertex buffer."); let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, @@ -231,8 +227,7 @@ fn main() { 0, vertex_input_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut slice = Align::new( vert_ptr, align_of::() as u64, @@ -267,12 +262,11 @@ fn main() { let uniform_color_buffer_memory_req = base .device .get_buffer_memory_requirements(uniform_color_buffer); - let uniform_color_buffer_memory_index = - find_memorytype_index( - &uniform_color_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + let uniform_color_buffer_memory_index = find_memorytype_index( + &uniform_color_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the vertex buffer."); let uniform_color_buffer_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, @@ -291,8 +285,7 @@ fn main() { 0, uniform_color_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut uniform_aligned_slice = Align::new( uniform_ptr, align_of::() as u64, @@ -319,12 +312,11 @@ fn main() { }; let image_buffer = base.device.create_buffer(&image_buffer_info, None).unwrap(); let image_buffer_memory_req = base.device.get_buffer_memory_requirements(image_buffer); - let image_buffer_memory_index = - find_memorytype_index( - &image_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + let image_buffer_memory_index = find_memorytype_index( + &image_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the vertex buffer."); let image_buffer_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, @@ -343,8 +335,7 @@ fn main() { 0, image_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut image_slice = Align::new( image_ptr, std::mem::align_of::() as u64, @@ -382,12 +373,11 @@ fn main() { .create_image(&texture_create_info, None) .unwrap(); let texture_memory_req = base.device.get_image_memory_requirements(texture_image); - let texture_memory_index = - find_memorytype_index( - &texture_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::DEVICE_LOCAL, - ).expect("Unable to find suitable memory index for depth image."); + let texture_memory_index = find_memorytype_index( + &texture_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::DEVICE_LOCAL, + ).expect("Unable to find suitable memory index for depth image."); let texture_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, @@ -882,8 +872,7 @@ fn main() { std::u64::MAX, base.present_complete_semaphore, vk::Fence::null(), - ) - .unwrap(); + ).unwrap(); let clear_values = [ vk::ClearValue { color: vk::ClearColorValue { diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index f213b6e..213127c 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -110,8 +110,7 @@ fn main() { base.device .create_framebuffer(&frame_buffer_create_info, None) .unwrap() - }) - .collect(); + }).collect(); let index_buffer_data = [0u32, 1, 2]; let index_buffer_info = vk::BufferCreateInfo { s_type: vk::StructureType::BUFFER_CREATE_INFO, @@ -125,12 +124,11 @@ fn main() { }; let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); - let index_buffer_memory_index = - find_memorytype_index( - &index_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the index buffer."); + let index_buffer_memory_index = find_memorytype_index( + &index_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the index buffer."); let index_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, p_next: ptr::null(), @@ -148,8 +146,7 @@ fn main() { 0, index_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut index_slice = Align::new( index_ptr, align_of::() as u64, @@ -178,12 +175,11 @@ fn main() { let vertex_input_buffer_memory_req = base .device .get_buffer_memory_requirements(vertex_input_buffer); - let vertex_input_buffer_memory_index = - find_memorytype_index( - &vertex_input_buffer_memory_req, - &base.device_memory_properties, - vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + let vertex_input_buffer_memory_index = find_memorytype_index( + &vertex_input_buffer_memory_req, + &base.device_memory_properties, + vk::MemoryPropertyFlags::HOST_VISIBLE, + ).expect("Unable to find suitable memorytype for the vertex buffer."); let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, @@ -216,8 +212,7 @@ fn main() { 0, vertex_input_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ) - .unwrap(); + ).unwrap(); let mut vert_align = Align::new( vert_ptr, align_of::() as u64, @@ -467,8 +462,7 @@ fn main() { std::u64::MAX, base.present_complete_semaphore, vk::Fence::null(), - ) - .unwrap(); + ).unwrap(); let clear_values = [ vk::ClearValue { color: vk::ClearColorValue { diff --git a/examples/src/lib.rs b/examples/src/lib.rs index db77214..195903c 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -4,13 +4,13 @@ extern crate ash; extern crate winapi; extern crate winit; -#[cfg(target_os = "macos")] -extern crate objc; #[cfg(target_os = "macos")] extern crate cocoa; #[cfg(target_os = "macos")] extern crate metal_rs as metal; #[cfg(target_os = "macos")] +extern crate objc; +#[cfg(target_os = "macos")] use cocoa::appkit::{NSView, NSWindow}; #[cfg(target_os = "macos")] use cocoa::base::id as cocoa_id; @@ -21,18 +21,18 @@ use objc::runtime::YES; #[cfg(target_os = "macos")] use std::mem; -use ash::vk; -use ash::Device; -use ash::Entry; -use ash::Instance; -pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0}; -use ash::extensions::{DebugReport, Surface, Swapchain}; +#[cfg(target_os = "macos")] +use ash::extensions::MacOSSurface; #[cfg(target_os = "windows")] use ash::extensions::Win32Surface; #[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))] use ash::extensions::XlibSurface; -#[cfg(target_os = "macos")] -use ash::extensions::MacOSSurface; +use ash::extensions::{DebugReport, Surface, Swapchain}; +pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0}; +use ash::vk; +use ash::Device; +use ash::Entry; +use ash::Instance; use std::cell::RefCell; use std::default::Default; use std::ffi::{CStr, CString}; @@ -125,8 +125,7 @@ unsafe fn create_surface( window: x11_window as vk::Window, dpy: x11_display as *mut vk::Display, }; - let xlib_surface_loader = - XlibSurface::new(entry, instance); + let xlib_surface_loader = XlibSurface::new(entry, instance); xlib_surface_loader.create_xlib_surface_khr(&x11_create_info, None) } @@ -156,11 +155,10 @@ unsafe fn create_surface( s_type: vk::StructureType::MACOS_SURFACE_CREATE_INFO_M, p_next: ptr::null(), flags: Default::default(), - p_view: window.get_nsview() as *const c_void + p_view: window.get_nsview() as *const c_void, }; - let macos_surface_loader = - MacOSSurface::new(entry, instance); + let macos_surface_loader = MacOSSurface::new(entry, instance); macos_surface_loader.create_mac_os_surface_mvk(&create_info, None) } @@ -183,8 +181,7 @@ unsafe fn create_surface( hinstance: hinstance, hwnd: hwnd as *const c_void, }; - let win32_surface_loader = - Win32Surface::new(entry, instance); + let win32_surface_loader = Win32Surface::new(entry, instance); win32_surface_loader.create_win32_surface_khr(&win32_create_info, None) } @@ -376,8 +373,7 @@ impl ExampleBase { pfn_callback: Some(vulkan_debug_callback), p_user_data: ptr::null_mut(), }; - let debug_report_loader = - DebugReport::new(&entry, &instance); + let debug_report_loader = DebugReport::new(&entry, &instance); let debug_call_back = debug_report_loader .create_debug_report_callback_ext(&debug_info, None) .unwrap(); @@ -385,8 +381,7 @@ impl ExampleBase { let pdevices = instance .enumerate_physical_devices() .expect("Physical device error"); - let surface_loader = - Surface::new(&entry, &instance); + let surface_loader = Surface::new(&entry, &instance); let (pdevice, queue_family_index) = pdevices .iter() .map(|pdevice| { @@ -396,8 +391,8 @@ impl ExampleBase { .enumerate() .filter_map(|(index, ref info)| { let supports_graphic_and_surface = - info.queue_flags.contains(vk::QueueFlags::GRAPHICS) && surface_loader - .get_physical_device_surface_support_khr( + info.queue_flags.contains(vk::QueueFlags::GRAPHICS) + && surface_loader.get_physical_device_surface_support_khr( *pdevice, index as u32, surface, @@ -487,8 +482,7 @@ impl ExampleBase { .cloned() .find(|&mode| mode == vk::PresentModeKHR::MAILBOX) .unwrap_or(vk::PresentModeKHR::FIFO); - let swapchain_loader = - Swapchain::new(&instance, &device); + let swapchain_loader = Swapchain::new(&instance, &device); let swapchain_create_info = vk::SwapchainCreateInfoKHR { s_type: vk::StructureType::SWAPCHAIN_CREATE_INFO_KHR, p_next: ptr::null(), diff --git a/generator/src/lib.rs b/generator/src/lib.rs index db2e765..cfe3c60 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -531,13 +531,13 @@ impl CommandExt for vkxml::Command { } fn function_type(&self) -> FunctionType { - let is_first_param_device = self.param + let is_first_param_device = self + .param .get(0) .map(|field| match field.basetype.as_str() { "VkDevice" | "VkCommandBuffer" | "VkQueue" => true, _ => false, - }) - .unwrap_or(false); + }).unwrap_or(false); match self.name.as_str() { "vkGetInstanceProcAddr" => FunctionType::Static, "vkCreateInstance" @@ -643,7 +643,8 @@ impl FieldExt for vkxml::Field { fn type_tokens(&self) -> Tokens { let ty = name_to_tokens(&self.basetype); - let pointer = self.reference + let pointer = self + .reference .as_ref() .map(|r| r.to_tokens(self.is_const)) .unwrap_or(quote!{}); @@ -652,7 +653,8 @@ impl FieldExt for vkxml::Field { }; let array = self.array.as_ref().and_then(|arraytype| match arraytype { vkxml::ArrayType::Static => { - let size = self.size + let size = self + .size .as_ref() .or_else(|| self.size_enumref.as_ref()) .expect("Should have size"); @@ -700,23 +702,21 @@ fn generate_function_pointers<'a>( } else { return false; } - }) - .collect(); + }).collect(); let params: Vec> = commands .iter() .map(|cmd| { - let params: Vec<_> = cmd.param + let params: Vec<_> = cmd + .param .iter() .map(|field| { let name = field.param_ident(); let ty = field.type_tokens(); (name, ty) - }) - .collect(); + }).collect(); params - }) - .collect(); + }).collect(); let params_names: Vec> = params .iter() @@ -725,8 +725,7 @@ fn generate_function_pointers<'a>( .iter() .map(|&(param_name, _)| param_name) .collect() - }) - .collect(); + }).collect(); let param_names_ref = ¶ms_names; let expanded_params: Vec<_> = params .iter() @@ -737,8 +736,7 @@ fn generate_function_pointers<'a>( quote!{ #(#inner_params_iter,)* } - }) - .collect(); + }).collect(); let expanded_params_unused: Vec<_> = params .iter() .map(|inner_params| { @@ -749,8 +747,7 @@ fn generate_function_pointers<'a>( quote!{ #(#inner_params_iter,)* } - }) - .collect(); + }).collect(); let expanded_params_ref = &expanded_params; let return_types: Vec<_> = commands @@ -768,17 +765,16 @@ fn generate_function_pointers<'a>( let signature_params: Vec> = pfn_commands .iter() .map(|cmd| { - let params: Vec<_> = cmd.param + let params: Vec<_> = cmd + .param .iter() .map(|field| { let name = field.param_ident(); let ty = field.type_tokens(); quote! { #name: #ty } - }) - .collect(); + }).collect(); params - }) - .collect(); + }).collect(); let signature_params_ref = &signature_params; let pfn_return_types: Vec<_> = pfn_commands @@ -869,8 +865,7 @@ pub fn generate_extension_constants<'a>( .filter_map(|item| match item { vk_parse::ExtensionItem::Require { items, .. } => Some(items.iter()), _ => None, - }) - .flat_map(|iter| iter); + }).flat_map(|iter| iter); let enum_tokens = items.filter_map(|item| match item { vk_parse::InterfaceItem::Enum(_enum) => { use vk_parse::EnumSpec; @@ -940,8 +935,7 @@ pub fn generate_extension_commands<'a>( })) } _ => None, - }) - .flat_map(|iter| iter) + }).flat_map(|iter| iter) .collect_vec(); let name = format!("{}Fn", extension_name.to_camel_case()); let ident = Ident::from(&name[2..]); @@ -1048,8 +1042,7 @@ pub fn bitflags_impl_block( let variant_ident = constant.variant_ident(enum_name); let tokens = constant.to_tokens(); (variant_ident, tokens) - }) - .collect_vec(); + }).collect_vec(); let notations = constants.iter().map(|constant| { constant.notation().map(|n| { @@ -1059,14 +1052,16 @@ pub fn bitflags_impl_block( }) }); - let variants = variants.iter().zip(notations.clone()).map( - |((variant_ident, value), ref notation)| { - quote!{ - #notation - pub const #variant_ident: Self = #ident(#value); - } - }, - ); + let variants = + variants + .iter() + .zip(notations.clone()) + .map(|((variant_ident, value), ref notation)| { + quote!{ + #notation + pub const #variant_ident: Self = #ident(#value); + } + }); quote!{ impl #ident { #(#variants)* @@ -1088,8 +1083,7 @@ pub fn generate_enum<'a>( .filter_map(|elem| match *elem { vkxml::EnumerationElement::Enum(ref constant) => Some(constant), _ => None, - }) - .collect_vec(); + }).collect_vec(); let values = const_values.entry(ident.clone()).or_insert_with(Vec::new); for constant in &constants { const_cache.insert(constant.name.as_str()); @@ -1193,8 +1187,7 @@ fn is_static_array(field: &vkxml::Field) -> bool { .map(|ty| match ty { vkxml::ArrayType::Static => true, _ => false, - }) - .unwrap_or(false) + }).unwrap_or(false) } pub fn derive_default(_struct: &vkxml::Struct) -> Option { let name = name_to_tokens(&_struct.name); @@ -1366,10 +1359,9 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option { // Associated _count members if field.array.is_some() { if let Some(ref array_size) = field.size { - if !array_size.starts_with("latexmath") - && !nofilter_count_members - .iter() - .any(|n| *n == &(_struct.name.clone() + "." + field_name)) + if !array_size.starts_with("latexmath") && !nofilter_count_members + .iter() + .any(|n| *n == &(_struct.name.clone() + "." + field_name)) { return Some((*array_size).clone()); } @@ -1382,8 +1374,7 @@ pub fn derive_setters(_struct: &vkxml::Struct) -> Option { } None - }) - .collect(); + }).collect(); let setters = members.clone().filter_map(|field| { let param_ident = field.param_ident(); @@ -1704,13 +1695,11 @@ pub fn generate_feature<'a>( } else { None } - }) - .collect() + }).collect() } else { vec![] } - }) - .filter_map(|cmd_ref| commands.get(&cmd_ref.name)) + }).filter_map(|cmd_ref| commands.get(&cmd_ref.name)) .fold( (Vec::new(), Vec::new(), Vec::new(), Vec::new()), |mut acc, &cmd_ref| { @@ -1873,59 +1862,57 @@ pub fn write_source_code(path: &Path) { .filter_map(|item| match item { vk_parse::RegistryItem::Extensions { items: ext, .. } => Some(ext), _ => None, - }) - .nth(0) + }).nth(0) .expect("extension"); let spec = vk_parse::parse_file_as_vkxml(path); - let commands: HashMap = spec.elements + let commands: HashMap = spec + .elements .iter() .filter_map(|elem| match elem { vkxml::RegistryElement::Commands(ref cmds) => Some(cmds), _ => None, - }) - .flat_map(|cmds| cmds.elements.iter().map(|cmd| (cmd.name.clone(), cmd))) + }).flat_map(|cmds| cmds.elements.iter().map(|cmd| (cmd.name.clone(), cmd))) .collect(); - let features: Vec<&vkxml::Feature> = spec.elements + let features: Vec<&vkxml::Feature> = spec + .elements .iter() .filter_map(|elem| match elem { vkxml::RegistryElement::Features(ref features) => Some(features), _ => None, - }) - .flat_map(|features| features.elements.iter()) + }).flat_map(|features| features.elements.iter()) .collect(); - let definitions: Vec<&vkxml::DefinitionsElement> = spec.elements + let definitions: Vec<&vkxml::DefinitionsElement> = spec + .elements .iter() .filter_map(|elem| match elem { vkxml::RegistryElement::Definitions(ref definitions) => Some(definitions), _ => None, - }) - .flat_map(|definitions| definitions.elements.iter()) + }).flat_map(|definitions| definitions.elements.iter()) .collect(); - let enums: Vec<&vkxml::Enumeration> = spec.elements + let enums: Vec<&vkxml::Enumeration> = spec + .elements .iter() .filter_map(|elem| match elem { vkxml::RegistryElement::Enums(ref enums) => Some(enums), _ => None, - }) - .flat_map(|enums| { + }).flat_map(|enums| { enums.elements.iter().filter_map(|_enum| match *_enum { vkxml::EnumsElement::Enumeration(ref e) => Some(e), _ => None, }) - }) - .collect(); + }).collect(); - let constants: Vec<&vkxml::Constant> = spec.elements + let constants: Vec<&vkxml::Constant> = spec + .elements .iter() .filter_map(|elem| match elem { vkxml::RegistryElement::Constants(ref constants) => Some(constants), _ => None, - }) - .flat_map(|constants| constants.elements.iter()) + }).flat_map(|constants| constants.elements.iter()) .collect(); let mut fn_cache = HashSet::new(); @@ -1958,16 +1945,14 @@ pub fn write_source_code(path: &Path) { &mut const_values, &mut fn_cache, ) - }) - .collect_vec(); + }).collect_vec(); let union_types = definitions .iter() .filter_map(|def| match def { vkxml::DefinitionsElement::Union(ref union) => Some(union.name.as_str()), _ => None, - }) - .collect::>(); + }).collect::>(); let definition_code: Vec<_> = definitions .into_iter() diff --git a/rustfmt.toml b/rustfmt.toml index 5bcb444..d100efd 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1 @@ -max_width = 100 -error_on_line_overflow = false \ No newline at end of file +max_width = 100 \ No newline at end of file