Skip to content

Commit

Permalink
Replace const fn name() with associated NAME constants
Browse files Browse the repository at this point in the history
`CStr::from_bytes_with_nul_unchecked` is `const`-stable since Rust 1.59,
and our advertised MSRV is already at 1.60 so it is high time to finally
turn these inlined `name()` functions into associated constants (which
is a breaking change in itself that cannot be backported).
  • Loading branch information
MarijnS95 committed Mar 9, 2023
1 parent 7b3df84 commit 3a63054
Show file tree
Hide file tree
Showing 70 changed files with 901 additions and 1,888 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Replaced builders with lifetimes/setters directly on Vulkan structs (#602)
- Inlined struct setters (#602)
- Bumped MSRV from 1.59 to 1.60 (#709)
- Replace `const fn name()` with associated `NAME` constants (#715)

### Removed

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport};
#[cfg(all(unix, not(target_os = "android")))]
fn extension_names() -> Vec<*const i8> {
vec![
Surface::name().as_ptr(),
XlibSurface::name().as_ptr(),
DebugReport::name().as_ptr()
Surface::NAME.as_ptr(),
XlibSurface::NAME.as_ptr(),
DebugReport::NAME.as_ptr()
]
}
```
Expand Down
24 changes: 12 additions & 12 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,48 @@ pub fn enumerate_required_extensions(
let extensions = match display_handle {
RawDisplayHandle::Windows(_) => {
const WINDOWS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::Win32Surface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::Win32Surface::NAME.as_ptr(),
];
&WINDOWS_EXTS
}

RawDisplayHandle::Wayland(_) => {
const WAYLAND_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::WaylandSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::WaylandSurface::NAME.as_ptr(),
];
&WAYLAND_EXTS
}

RawDisplayHandle::Xlib(_) => {
const XLIB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XlibSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::XlibSurface::NAME.as_ptr(),
];
&XLIB_EXTS
}

RawDisplayHandle::Xcb(_) => {
const XCB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::XcbSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::XcbSurface::NAME.as_ptr(),
];
&XCB_EXTS
}

RawDisplayHandle::Android(_) => {
const ANDROID_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::AndroidSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
khr::AndroidSurface::NAME.as_ptr(),
];
&ANDROID_EXTS
}

RawDisplayHandle::AppKit(_) | RawDisplayHandle::UiKit(_) => {
const METAL_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
khr::Surface::NAME.as_ptr(),
ext::MetalSurface::NAME.as_ptr(),
];
&METAL_EXTS
}
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/acquire_drm_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ impl AcquireDrmDisplay {
.assume_init_on_success(display)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtAcquireDrmDisplayFn::name()
}
pub const NAME: &CStr = vk::ExtAcquireDrmDisplayFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtAcquireDrmDisplayFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl BufferDeviceAddress {
(self.fp.get_buffer_device_address_ext)(self.handle, info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtBufferDeviceAddressFn::name()
}
pub const NAME: &CStr = vk::ExtBufferDeviceAddressFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtBufferDeviceAddressFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ impl CalibratedTimestamps {
.result_with_success((timestamps, max_deviation))
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtCalibratedTimestampsFn::name()
}
pub const NAME: &CStr = vk::ExtCalibratedTimestampsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtCalibratedTimestampsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ impl DebugMarker {
(self.fp.cmd_debug_marker_insert_ext)(command_buffer, marker_info);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugMarkerFn::name()
}
pub const NAME: &CStr = vk::ExtDebugMarkerFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugMarkerFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ impl DebugReport {
.result_with_success(debug_cb)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugReportFn::name()
}
pub const NAME: &CStr = vk::ExtDebugReportFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugReportFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ impl DebugUtils {
);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDebugUtilsFn::name()
}
pub const NAME: &CStr = vk::ExtDebugUtilsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDebugUtilsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/descriptor_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ impl DescriptorBuffer {
.result()
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtDescriptorBufferFn::name()
}
pub const NAME: &CStr = vk::ExtDescriptorBufferFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtDescriptorBufferFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ impl ExtendedDynamicState {
)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicStateFn::name()
}
pub const NAME: &CStr = vk::ExtExtendedDynamicStateFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicStateFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ impl ExtendedDynamicState2 {
)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicState2Fn::name()
}
pub const NAME: &CStr = vk::ExtExtendedDynamicState2Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicState2Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/extended_dynamic_state3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ impl ExtendedDynamicState3 {
(self.fp.cmd_set_coverage_reduction_mode_nv)(command_buffer, coverage_reduction_mode)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtExtendedDynamicState3Fn::name()
}
pub const NAME: &CStr = vk::ExtExtendedDynamicState3Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtExtendedDynamicState3Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/full_screen_exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl FullScreenExclusive {
.result_with_success(present_modes)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtFullScreenExclusiveFn::name()
}
pub const NAME: &CStr = vk::ExtFullScreenExclusiveFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtFullScreenExclusiveFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/headless_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl HeadlessSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtHeadlessSurfaceFn::name()
}
pub const NAME: &CStr = vk::ExtHeadlessSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtHeadlessSurfaceFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/image_compression_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl ImageCompressionControl {
(self.fp.get_image_subresource_layout2_ext)(self.handle, image, subresource, layout)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtImageCompressionControlFn::name()
}
pub const NAME: &CStr = vk::ExtImageCompressionControlFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtImageCompressionControlFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/image_drm_format_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ impl ImageDrmFormatModifier {
.result()
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtImageDrmFormatModifierFn::name()
}
pub const NAME: &CStr = vk::ExtImageDrmFormatModifierFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtImageDrmFormatModifierFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/mesh_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ impl MeshShader {
);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtMeshShaderFn::name()
}
pub const NAME: &CStr = vk::ExtMeshShaderFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtMeshShaderFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/metal_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl MetalSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtMetalSurfaceFn::name()
}
pub const NAME: &CStr = vk::ExtMetalSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtMetalSurfaceFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/physical_device_drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ impl PhysicalDeviceDrm {
props_drm
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtPhysicalDeviceDrmFn::name()
}
pub const NAME: &CStr = vk::ExtPhysicalDeviceDrmFn::NAME;
}
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/private_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ impl PrivateData {
data
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtPrivateDataFn::name()
}
pub const NAME: &CStr = vk::ExtPrivateDataFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtPrivateDataFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/sample_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl SampleLocations {
(self.fp.cmd_set_sample_locations_ext)(command_buffer, sample_locations_info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtSampleLocationsFn::name()
}
pub const NAME: &CStr = vk::ExtSampleLocationsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtSampleLocationsFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ impl ToolingInfo {
})
}

#[inline]
pub const fn name() -> &'static CStr {
vk::ExtToolingInfoFn::name()
}
pub const NAME: &CStr = vk::ExtToolingInfoFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::ExtToolingInfoFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,7 @@ impl AccelerationStructure {
size_info
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrAccelerationStructureFn::name()
}
pub const NAME: &CStr = vk::KhrAccelerationStructureFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrAccelerationStructureFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/android_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl AndroidSurface {
.result_with_success(surface)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrAndroidSurfaceFn::name()
}
pub const NAME: &CStr = vk::KhrAndroidSurfaceFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrAndroidSurfaceFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ impl BufferDeviceAddress {
(self.fp.get_device_memory_opaque_capture_address_khr)(self.handle, info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrBufferDeviceAddressFn::name()
}
pub const NAME: &CStr = vk::KhrBufferDeviceAddressFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrBufferDeviceAddressFn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/copy_commands2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ impl CopyCommands2 {
(self.fp.cmd_resolve_image2_khr)(command_buffer, resolve_image_info)
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrCopyCommands2Fn::name()
}
pub const NAME: &CStr = vk::KhrCopyCommands2Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrCopyCommands2Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/create_render_pass2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ impl CreateRenderPass2 {
(self.fp.cmd_end_render_pass2_khr)(command_buffer, subpass_end_info);
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrCreateRenderpass2Fn::name()
}
pub const NAME: &CStr = vk::KhrCreateRenderpass2Fn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrCreateRenderpass2Fn {
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/deferred_host_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl DeferredHostOperations {
(self.fp.get_deferred_operation_result_khr)(self.handle, operation).result()
}

#[inline]
pub const fn name() -> &'static CStr {
vk::KhrDeferredHostOperationsFn::name()
}
pub const NAME: &CStr = vk::KhrDeferredHostOperationsFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::KhrDeferredHostOperationsFn {
Expand Down
Loading

0 comments on commit 3a63054

Please sign in to comment.