Skip to content

Trait and internal derive macro for *_sys methods #413

Open
@ghost

Description

The sys, sys_mut and from_sys methods are placed on a lot of core wrappers, and also on the GodotObject trait (to_sys has the same signature as sys elsewhere). It might make sense to group them into a trait, which can reduce duplication and enable possible generic code later. The trait can be defined as:

unsafe trait SysConv: private::Sealed {
    type Sys;
    fn sys(&self) -> *const Self::Sys;
    fn from_sys(sys: *const Self::Sys) -> Self;

    fn sys_mut(&self) -> *mut Self::Sys {
        self.sys() as *mut _
    }
}

Additionally, an internal derive macro can be provided in impl/proc_macros for simple wrappers that are non-generic and have one tuple field or a sys field. This can reduce some code duplication in core.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: coreComponent: core (mod core_types, object, log, init, ...)quality-of-lifeNo new functionality, but improves ergonomics/internals

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions