Format code in doc comment code blocks (#2447)

* Format code in doc comment code blocks

* `cargo +nightly fmt`

* Finishing touches
This commit is contained in:
marc0246 2024-01-05 13:47:22 +01:00 committed by GitHub
parent 00b65b1299
commit eda954a670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 97 additions and 55 deletions

View File

@ -1,4 +1,5 @@
comment_width = 99
format_code_in_doc_comments = true
group_imports = "One"
imports_granularity = "Crate"
wrap_comments = true

View File

@ -6,7 +6,7 @@
//!
//! ```
//! mod vs {
//! vulkano_shaders::shader!{
//! vulkano_shaders::shader! {
//! ty: "vertex",
//! src: r"
//! #version 450

View File

@ -17,17 +17,21 @@ use winit::{
/// ## Examples
///
/// ```
/// use vulkano_util::context::{VulkanoConfig, VulkanoContext};
/// use vulkano_util::{
/// context::{VulkanoConfig, VulkanoContext},
/// window::VulkanoWindows,
/// };
/// use winit::event_loop::EventLoop;
/// use vulkano_util::window::VulkanoWindows;
///
/// #[test]
/// fn test() {
/// let context = VulkanoContext::new(VulkanoConfig::default());
/// let event_loop = EventLoop::new();
/// let mut vulkano_windows = VulkanoWindows::default();
/// let _id1 = vulkano_windows.create_window(&event_loop, &context, &Default::default(), |_| {});
/// let _id2 = vulkano_windows.create_window(&event_loop, &context, &Default::default(), |_| {});
/// let _id1 =
/// vulkano_windows.create_window(&event_loop, &context, &Default::default(), |_| {});
/// let _id2 =
/// vulkano_windows.create_window(&event_loop, &context, &Default::default(), |_| {});
///
/// // You should now have two windows.
/// }

View File

@ -7,7 +7,10 @@
//!
//! ```no_run
//! use vulkano::{
//! device::{physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Features, QueueCreateInfo},
//! device::{
//! physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Features,
//! QueueCreateInfo,
//! },
//! instance::{Instance, InstanceExtensions},
//! Version, VulkanLibrary,
//! };
@ -23,7 +26,8 @@
//! let physical_device = instance
//! .enumerate_physical_devices()
//! .unwrap_or_else(|err| panic!("Couldn't enumerate physical devices: {:?}", err))
//! .next().expect("No physical device");
//! .next()
//! .expect("No physical device");
//!
//! // Here is the device-creating code.
//! let device = {
@ -43,7 +47,7 @@
//! },
//! ) {
//! Ok(d) => d,
//! Err(err) => panic!("Couldn't build device: {:?}", err)
//! Err(err) => panic!("Couldn't build device: {:?}", err),
//! }
//! };
//! ```

View File

@ -62,7 +62,10 @@ use std::{mem::MaybeUninit, num::NonZeroU64, ops::RangeInclusive, ptr, sync::Arc
/// use vulkano::image::sampler::{Sampler, SamplerCreateInfo};
///
/// # let device: std::sync::Arc<vulkano::device::Device> = return;
/// let _sampler = Sampler::new(device.clone(), SamplerCreateInfo::simple_repeat_linear_no_mipmap());
/// let _sampler = Sampler::new(
/// device.clone(),
/// SamplerCreateInfo::simple_repeat_linear_no_mipmap(),
/// );
/// ```
///
/// More detailed sampler creation:
@ -71,14 +74,17 @@ use std::{mem::MaybeUninit, num::NonZeroU64, ops::RangeInclusive, ptr, sync::Arc
/// use vulkano::image::sampler::{Filter, Sampler, SamplerAddressMode, SamplerCreateInfo};
///
/// # let device: std::sync::Arc<vulkano::device::Device> = return;
/// let _sampler = Sampler::new(device.clone(), SamplerCreateInfo {
/// mag_filter: Filter::Linear,
/// min_filter: Filter::Linear,
/// address_mode: [SamplerAddressMode::Repeat; 3],
/// mip_lod_bias: 1.0,
/// lod: 0.0..=100.0,
/// ..Default::default()
/// })
/// let _sampler = Sampler::new(
/// device.clone(),
/// SamplerCreateInfo {
/// mag_filter: Filter::Linear,
/// min_filter: Filter::Linear,
/// address_mode: [SamplerAddressMode::Repeat; 3],
/// mip_lod_bias: 1.0,
/// lod: 0.0..=100.0,
/// ..Default::default()
/// },
/// )
/// .unwrap();
/// ```
#[derive(Debug)]

View File

@ -21,12 +21,13 @@
//! let _callback = unsafe {
//! DebugUtilsMessenger::new(
//! instance,
//! DebugUtilsMessengerCreateInfo::user_callback(
//! DebugUtilsMessengerCallback::new(|message_severity, message_type, callback_data| {
//! DebugUtilsMessengerCreateInfo::user_callback(DebugUtilsMessengerCallback::new(
//! |message_severity, message_type, callback_data| {
//! println!("Debug callback: {:?}", callback_data.message);
//! }),
//! ),
//! ).ok()
//! },
//! )),
//! )
//! .ok()
//! };
//! ```
//!

View File

@ -89,7 +89,11 @@ impl LayerProperties {
/// let library = VulkanLibrary::new().unwrap();
///
/// for layer in library.layer_properties().unwrap() {
/// println!("Layer {} - Version: {}", layer.name(), layer.implementation_version());
/// println!(
/// "Layer {} - Version: {}",
/// layer.name(),
/// layer.implementation_version(),
/// );
/// }
/// ```
#[inline]

View File

@ -29,7 +29,10 @@
//! # let library = VulkanLibrary::new().unwrap();
//! # let instance = Instance::new(library, Default::default()).unwrap();
//! for physical_device in instance.enumerate_physical_devices().unwrap() {
//! println!("Available device: {}", physical_device.properties().device_name);
//! println!(
//! "Available device: {}",
//! physical_device.properties().device_name,
//! );
//! }
//! ```
//!
@ -127,10 +130,8 @@ include!(concat!(env!("OUT_DIR"), "/instance_extensions.rs"));
/// };
///
/// let library = VulkanLibrary::new().unwrap();
/// let _instance = Instance::new(
/// library,
/// InstanceCreateInfo::application_from_cargo_toml(),
/// ).unwrap();
/// let _instance =
/// Instance::new(library, InstanceCreateInfo::application_from_cargo_toml()).unwrap();
/// # }
/// ```
///
@ -192,7 +193,7 @@ include!(concat!(env!("OUT_DIR"), "/instance_extensions.rs"));
/// let extensions = InstanceExtensions {
/// khr_surface: true,
/// khr_android_surface: true,
/// .. InstanceExtensions::empty()
/// ..InstanceExtensions::empty()
/// };
///
/// let instance = Instance::new(
@ -241,7 +242,8 @@ include!(concat!(env!("OUT_DIR"), "/instance_extensions.rs"));
///
/// // For the sake of the example, we activate all the layers that
/// // contain the word "foo" in their description.
/// let layers: Vec<_> = library.layer_properties()?
/// let layers: Vec<_> = library
/// .layer_properties()?
/// .filter(|l| l.description().contains("foo"))
/// .collect();
///
@ -637,7 +639,10 @@ impl Instance {
/// # let library = VulkanLibrary::new().unwrap();
/// # let instance = Instance::new(library, Default::default()).unwrap();
/// for physical_device in instance.enumerate_physical_devices().unwrap() {
/// println!("Available device: {}", physical_device.properties().device_name);
/// println!(
/// "Available device: {}",
/// physical_device.properties().device_name,
/// );
/// }
/// ```
pub fn enumerate_physical_devices(

View File

@ -1668,7 +1668,9 @@ impl Default for MappedMemoryRange {
/// # Examples
///
/// ```
/// use vulkano::memory::{DeviceMemory, MappedDeviceMemory, MemoryAllocateInfo, MemoryPropertyFlags};
/// use vulkano::memory::{
/// DeviceMemory, MappedDeviceMemory, MemoryAllocateInfo, MemoryPropertyFlags,
/// };
///
/// # let device: std::sync::Arc<vulkano::device::Device> = return;
/// // The memory type must be mappable.
@ -1677,7 +1679,10 @@ impl Default for MappedMemoryRange {
/// .memory_properties()
/// .memory_types
/// .iter()
/// .position(|t| t.property_flags.intersects(MemoryPropertyFlags::HOST_VISIBLE))
/// .position(|t| {
/// t.property_flags
/// .intersects(MemoryPropertyFlags::HOST_VISIBLE)
/// })
/// .map(|i| i as u32)
/// .unwrap(); // Vk specs guarantee that this can't fail
///

View File

@ -12,7 +12,12 @@
//! ```
//! // Enumerating memory heaps.
//! # let physical_device: vulkano::device::physical::PhysicalDevice = return;
//! for (index, heap) in physical_device.memory_properties().memory_heaps.iter().enumerate() {
//! for (index, heap) in physical_device
//! .memory_properties()
//! .memory_heaps
//! .iter()
//! .enumerate()
//! {
//! println!("Heap #{:?} has a capacity of {:?} bytes", index, heap.size);
//! }
//! ```
@ -68,7 +73,8 @@
//! memory_type_index,
//! ..Default::default()
//! },
//! ).expect("Failed to allocate memory");
//! )
//! .expect("Failed to allocate memory");
//!
//! // The memory is automatically freed when `memory` is destroyed.
//! ```

View File

@ -50,8 +50,7 @@ impl PipelineCache {
/// ```
/// # use std::sync::Arc;
/// # use vulkano::device::Device;
/// use std::fs::File;
/// use std::io::Read;
/// use std::{fs::File, io::Read};
/// use vulkano::pipeline::cache::{PipelineCache, PipelineCacheCreateInfo};
/// # let device: Arc<Device> = return;
///
@ -76,8 +75,9 @@ impl PipelineCache {
/// PipelineCacheCreateInfo {
/// initial_data,
/// ..Default::default()
/// }
/// ).unwrap()
/// },
/// )
/// .unwrap()
/// };
/// ```
#[inline]
@ -178,9 +178,7 @@ impl PipelineCache {
/// # Examples
///
/// ```
/// use std::fs;
/// use std::fs::File;
/// use std::io::Write;
/// use std::{fs, fs::File, io::Write};
/// # use std::sync::Arc;
/// # use vulkano::pipeline::cache::PipelineCache;
///

View File

@ -62,7 +62,8 @@ mod framebuffer;
/// subpasses: vec![SubpassDescription::default()],
/// ..Default::default()
/// },
/// ).unwrap();
/// )
/// .unwrap();
/// ```
///
/// This example creates a render pass with no attachment and one single subpass that doesn't draw

View File

@ -58,8 +58,8 @@
//!
//! let extensions = InstanceExtensions {
//! khr_surface: true,
//! khr_win32_surface: true, // If you don't enable this, `from_hwnd` will fail.
//! .. InstanceExtensions::empty()
//! khr_win32_surface: true, // If you don't enable this, `from_hwnd` will fail.
//! ..InstanceExtensions::empty()
//! };
//!
//! Instance::new(
@ -86,7 +86,8 @@
//! hinstance,
//! window.hwnd() as ash::vk::HWND,
//! Some(window),
//! ).unwrap()
//! )
//! .unwrap()
//! };
//! ```
//!
@ -121,7 +122,7 @@
//! # use vulkano::device::DeviceExtensions;
//! let ext = DeviceExtensions {
//! khr_swapchain: true,
//! .. DeviceExtensions::empty()
//! ..DeviceExtensions::empty()
//! };
//! ```
//!
@ -265,7 +266,8 @@
//! ```
//! use vulkano::{
//! swapchain::{self, SwapchainCreateInfo, SwapchainPresentInfo},
//! sync::GpuFuture, Validated, VulkanError,
//! sync::GpuFuture,
//! Validated, VulkanError,
//! };
//!
//! // let (swapchain, images) = Swapchain::new(...);
@ -276,20 +278,25 @@
//!
//! loop {
//! if recreate_swapchain {
//! let (new_swapchain, new_images) = swapchain.recreate(SwapchainCreateInfo {
//! image_extent: [1024, 768],
//! ..swapchain.create_info()
//! })
//! .unwrap();
//! let (new_swapchain, new_images) = swapchain
//! .recreate(SwapchainCreateInfo {
//! image_extent: [1024, 768],
//! ..swapchain.create_info()
//! })
//! .unwrap();
//! swapchain = new_swapchain;
//! images = new_images;
//! recreate_swapchain = false;
//! }
//!
//! let (image_index, suboptimal, acq_future) =
//! match swapchain::acquire_next_image(swapchain.clone(), None).map_err(Validated::unwrap) {
//! match swapchain::acquire_next_image(swapchain.clone(), None).map_err(Validated::unwrap)
//! {
//! Ok(r) => r,
//! Err(VulkanError::OutOfDate) => { recreate_swapchain = true; continue; },
//! Err(VulkanError::OutOfDate) => {
//! recreate_swapchain = true;
//! continue;
//! }
//! Err(err) => panic!("{:?}", err),
//! };
//!