Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Unbuildable to crate root and rename to NonExhaustive #1818

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions vulkano/autogen/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
pub(crate) fn required_if_supported_extensions() -> Self {
Self {
#(#required_if_supported_extensions_items)*
_unbuildable: Unbuildable(())
_ne: crate::NonExhaustive(()),
}
}
}
Expand Down Expand Up @@ -358,11 +358,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
pub struct #struct_name {
#(#struct_items)*

/// This field ensures that an instance of this `Extensions` struct
/// can only be created through Vulkano functions and the update
/// syntax. This way, extensions can be added to Vulkano without
/// breaking existing code.
pub _unbuildable: Unbuildable,
pub _ne: crate::NonExhaustive,
}

impl #struct_name {
Expand All @@ -371,7 +367,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
pub const fn none() -> Self {
Self {
#(#none_items)*
_unbuildable: Unbuildable(())
_ne: crate::NonExhaustive(()),
}
}

Expand All @@ -388,7 +384,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
pub const fn union(&self, other: &Self) -> Self {
Self {
#(#union_items)*
_unbuildable: Unbuildable(())
_ne: crate::NonExhaustive(()),
}
}

Expand All @@ -397,7 +393,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
pub const fn intersection(&self, other: &Self) -> Self {
Self {
#(#intersection_items)*
_unbuildable: Unbuildable(())
_ne: crate::NonExhaustive(()),
}
}

Expand All @@ -406,7 +402,7 @@ fn extensions_common_output(struct_name: Ident, members: &[ExtensionsMember]) ->
pub const fn difference(&self, other: &Self) -> Self {
Self {
#(#difference_items)*
_unbuildable: Unbuildable(())
_ne: crate::NonExhaustive(()),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion vulkano/src/device/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use crate::device::physical::PhysicalDevice;
pub use crate::extensions::{
ExtensionRestriction, ExtensionRestrictionError, OneOfRequirements, SupportedExtensionsError,
Unbuildable,
};
use crate::instance::InstanceExtensions;
use crate::Version;
Expand Down
5 changes: 0 additions & 5 deletions vulkano/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,3 @@ impl Display for OneOfRequirements {
Ok(())
}
}

/// This helper type can only be instantiated inside this module.
#[doc(hidden)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Unbuildable(pub(crate) ());
1 change: 0 additions & 1 deletion vulkano/src/instance/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use crate::check_errors;
pub use crate::extensions::{
ExtensionRestriction, ExtensionRestrictionError, OneOfRequirements, SupportedExtensionsError,
Unbuildable,
};
use crate::instance::loader;
use crate::instance::loader::LoadingError;
Expand Down
9 changes: 9 additions & 0 deletions vulkano/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,12 @@ fn check_errors(result: ash::vk::Result) -> Result<Success, Error> {
c => unreachable!("Unexpected error code returned by Vulkan: {}", c),
}
}

/// A helper type for non-exhaustive structs.
///
/// This type cannot be constructed outside Vulkano. Structures with a field of this type can only
/// be constructed by calling a function such as `Default::default()`. The effect is similar to the
/// standard Rust `#[non_exhaustive]` attribute, except that it does not prevent update syntax from
/// being used.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] // add traits as needed
pub struct NonExhaustive(pub(crate) ());