Skip to content

Commit

Permalink
Make GodotClass an unsafe trait and document usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Jul 17, 2023
1 parent 4802dd8 commit 0c88935
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion godot-codegen/src/class_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ fn make_class(class: &Class, class_name: &TyName, ctx: &mut Context) -> Generate
#methods
#constants
}
impl crate::obj::GodotClass for #class_name {
unsafe impl crate::obj::GodotClass for #class_name {
type Base = #base_ty;
type Declarer = crate::obj::dom::EngineDomain;
type Mem = crate::obj::mem::#memory;
Expand Down
11 changes: 8 additions & 3 deletions godot-core/src/obj/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use godot_ffi as sys;
///
/// The behavior of types implementing this trait is influenced by the associated types; check their documentation for information.
///
/// You wouldn't usually implement this trait yourself; use the [`GodotClass`](godot_macros::GodotClass) derive macro instead.
pub trait GodotClass: 'static
/// # Safety
///
/// Internal.
/// **You must not implement this trait yourself; use the [`GodotClass`](crate::bind::GodotClass) derive macro instead.**
pub unsafe trait GodotClass: 'static
where
Self: Sized,
{
Expand Down Expand Up @@ -51,7 +54,7 @@ where
}

/// Unit impl only exists to represent "no base", and is used for exactly one class: `Object`.
impl GodotClass for () {
unsafe impl GodotClass for () {
type Base = ();
type Declarer = dom::EngineDomain;
type Mem = mem::ManualMemory;
Expand Down Expand Up @@ -286,6 +289,8 @@ pub mod mem {
false
}
}

#[doc(hidden)]
pub trait PossiblyManual {}

/// Memory managed through Godot reference counter (always present).
Expand Down
2 changes: 1 addition & 1 deletion godot-macros/src/derive_godot_class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn transform(decl: Declaration) -> ParseResult<TokenStream> {
};

Ok(quote! {
impl ::godot::obj::GodotClass for #class_name {
unsafe impl ::godot::obj::GodotClass for #class_name {
type Base = ::godot::engine::#base_ty;
type Declarer = ::godot::obj::dom::UserDomain;
type Mem = <Self::Base as ::godot::obj::GodotClass>::Mem;
Expand Down
4 changes: 2 additions & 2 deletions godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ mod itest;
mod method_registration;
mod util;

/// Derive macro for [`GodotClass`](godot_core::obj::GodotClass) on structs. You should normally use
/// this macro, rather than implement `GodotClass` manually for your type.
/// Derive macro for [`GodotClass`](godot_core::obj::GodotClass) on structs. You must use this
/// macro; manual implementations of the `GodotClass` traits are not supported.
///
/// # Construction
///
Expand Down

0 comments on commit 0c88935

Please sign in to comment.