Skip to content

Commit 8dfe67b

Browse files
author
toasteater
committed
Use a private uninhabited type for Export impls without hints
This makes it no longer a breaking change to add hints for these types later, since the type can't be constructed, and can't be named except as an associated type, so it could not be used in a way that would break if we replace it with something else in safe code.
1 parent 64c4a3b commit 8dfe67b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

gdnative-core/src/nativescript/init/property.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ use accessor::{Getter, InvalidGetter, InvalidSetter, RawGetter, RawSetter, Sette
1919
/// Trait for exportable types.
2020
pub trait Export: ToVariant {
2121
/// A type-specific hint type that is valid for the type being exported.
22+
///
23+
/// If this type shows up as `NoHint`, a private, uninhabitable type indicating
24+
/// that there are no hints available for the time being, users *must* use `None`
25+
/// for properties of this type. This ensures that it will not be a breaking change
26+
/// to add a hint for the type later, since it supports no operations and cannot
27+
/// be named directly in user code.
2228
type Hint;
2329

2430
/// Returns `ExportInfo` given an optional typed hint.
@@ -319,6 +325,13 @@ impl Usage {
319325
mod impl_export {
320326
use super::*;
321327

328+
/// Hint type indicating that there are no hints available for the time being.
329+
///
330+
/// This is an inhabitable type that cannot be constructed. As a result, users
331+
/// *must* use `None` for the property hint when exporting types using this as
332+
/// the hint.
333+
pub enum NoHint {}
334+
322335
macro_rules! impl_export_for_int {
323336
($ty:ident) => {
324337
impl Export for $ty {
@@ -382,7 +395,7 @@ mod impl_export {
382395
macro_rules! impl_export_for_core_type_without_hint {
383396
($ty:ty: $variant_ty:ident) => {
384397
impl Export for $ty {
385-
type Hint = ();
398+
type Hint = NoHint;
386399
#[inline]
387400
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
388401
ExportInfo::new(VariantType::$variant_ty)
@@ -430,7 +443,7 @@ mod impl_export {
430443
where
431444
T: GodotObject,
432445
{
433-
type Hint = ();
446+
type Hint = NoHint;
434447
#[inline]
435448
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
436449
ExportInfo::resource_type::<T>()
@@ -442,7 +455,7 @@ mod impl_export {
442455
T: NativeClass,
443456
Instance<T, Shared>: ToVariant,
444457
{
445-
type Hint = ();
458+
type Hint = NoHint;
446459
#[inline]
447460
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
448461
ExportInfo::resource_type::<T::Base>()

0 commit comments

Comments
 (0)