Skip to content

Commit

Permalink
Merge #690
Browse files Browse the repository at this point in the history
690: Use a private uninhabited type for Export impls without hints r=halzy a=toasteater

No PRs in our godot-rust repo??? Time to change that!

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.

Close #684

Co-authored-by: toasteater <48371905+toasteater@users.noreply.github.com>
  • Loading branch information
bors[bot] and toasteater committed Feb 5, 2021
2 parents 633de6b + 8dfe67b commit 4bc7681
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gdnative-core/src/nativescript/init/property.rs
Expand Up @@ -19,6 +19,12 @@ use accessor::{Getter, InvalidGetter, InvalidSetter, RawGetter, RawSetter, Sette
/// Trait for exportable types.
pub trait Export: ToVariant {
/// A type-specific hint type that is valid for the type being exported.
///
/// If this type shows up as `NoHint`, a private, uninhabitable type indicating
/// that there are no hints available for the time being, users *must* use `None`
/// for properties of this type. This ensures that it will not be a breaking change
/// to add a hint for the type later, since it supports no operations and cannot
/// be named directly in user code.
type Hint;

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

/// Hint type indicating that there are no hints available for the time being.
///
/// This is an inhabitable type that cannot be constructed. As a result, users
/// *must* use `None` for the property hint when exporting types using this as
/// the hint.
pub enum NoHint {}

macro_rules! impl_export_for_int {
($ty:ident) => {
impl Export for $ty {
Expand Down Expand Up @@ -382,7 +395,7 @@ mod impl_export {
macro_rules! impl_export_for_core_type_without_hint {
($ty:ty: $variant_ty:ident) => {
impl Export for $ty {
type Hint = ();
type Hint = NoHint;
#[inline]
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
ExportInfo::new(VariantType::$variant_ty)
Expand Down Expand Up @@ -430,7 +443,7 @@ mod impl_export {
where
T: GodotObject,
{
type Hint = ();
type Hint = NoHint;
#[inline]
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
ExportInfo::resource_type::<T>()
Expand All @@ -442,7 +455,7 @@ mod impl_export {
T: NativeClass,
Instance<T, Shared>: ToVariant,
{
type Hint = ();
type Hint = NoHint;
#[inline]
fn export_info(_hint: Option<Self::Hint>) -> ExportInfo {
ExportInfo::resource_type::<T::Base>()
Expand Down

0 comments on commit 4bc7681

Please sign in to comment.