Skip to content

Commit

Permalink
Move Unbuildable to crate root and rename to NonExhaustive (#1818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua authored Feb 6, 2022
1 parent 0a45d84 commit 4f09439
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
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) ());

0 comments on commit 4f09439

Please sign in to comment.