Struct RawPtr
pub struct RawPtr<P>where
P: FfiRawPointer,{ /* private fields */ }Expand description
Wrapper around a raw pointer, providing ToGodot/FromGodot for FFI passing.
This type allows raw pointers to be passed through the Godot FFI boundary. The pointer is converted to its memory address (as i64)
for FFI purposes.
You might need this in #[func], in dynamic calls (Object.call) or other scenarios where you have to interface with Godot’s low-level
pointer APIs. These pointers typically refer to GDExtension native structures, but there are a few other cases (e.g. *const u8 for
C char arrays).
§Example
use godot::meta::{RawPtr, ToGodot};
use godot::classes::native::AudioFrame;
let frame = AudioFrame { left: 0.0, right: 1.0 };
let ptr: *const AudioFrame = &raw const frame;
// SAFETY: we keep `frame` alive while using `wrapped`.
let wrapped = unsafe { RawPtr::new(ptr) };
let variant = wrapped.to_variant();Implementations§
§impl<P> RawPtr<P>where
P: FfiRawPointer,
impl<P> RawPtr<P>where
P: FfiRawPointer,
pub unsafe fn new(ptr: P) -> RawPtr<P>
pub unsafe fn new(ptr: P) -> RawPtr<P>
Constructs a new RawPtr from a raw pointer.
§Safety
The pointer must remain valid as long as a Godot API accesses its value. Special care is necessary in #[func] and I* virtual
function return types: if the pointer refers to a local variable, it will become immediately dangling, causing undefined behavior.
pub unsafe fn null() -> RawPtr<P>
pub unsafe fn null() -> RawPtr<P>
Constructs a new RawPtr wrapping a null pointer.
§Safety
You must ensure that Godot can handle null pointers in the specific Godot API where this value will be used.
pub fn ptr(self) -> P
pub fn ptr(self) -> P
Returns the wrapped raw pointer.
Trait Implementations§
§impl<P> Clone for RawPtr<P>where
P: Clone + FfiRawPointer,
impl<P> Clone for RawPtr<P>where
P: Clone + FfiRawPointer,
§impl<P> Debug for RawPtr<P>where
P: Debug + FfiRawPointer,
impl<P> Debug for RawPtr<P>where
P: Debug + FfiRawPointer,
§impl<P> FromGodot for RawPtr<P>where
P: FfiRawPointer + 'static,
impl<P> FromGodot for RawPtr<P>where
P: FfiRawPointer + 'static,
§fn try_from_godot(
via: <RawPtr<P> as GodotConvert>::Via,
) -> Result<RawPtr<P>, ConvertError>
fn try_from_godot( via: <RawPtr<P> as GodotConvert>::Via, ) -> Result<RawPtr<P>, ConvertError>
Err on failure.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant, returning Err on failure.