RawPtr

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,

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>

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

Returns the wrapped raw pointer.

Trait Implementations§

§

impl<P> Clone for RawPtr<P>
where P: Clone + FfiRawPointer,

§

fn clone(&self) -> RawPtr<P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<P> Debug for RawPtr<P>
where P: Debug + FfiRawPointer,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<P> FromGodot for RawPtr<P>
where P: FfiRawPointer + 'static,

§

fn try_from_godot( via: <RawPtr<P> as GodotConvert>::Via, ) -> Result<RawPtr<P>, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl<P> GodotConvert for RawPtr<P>
where P: FfiRawPointer + 'static,

§

type Via = RawPtr<P>

The type through which Self is represented in Godot.
§

impl<P> PartialEq for RawPtr<P>

§

fn eq(&self, other: &RawPtr<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<P> ToGodot for RawPtr<P>
where P: FfiRawPointer + 'static,

§

type Pass = ByValue

Whether arguments of this type are passed by value or by reference. Read more
§

fn to_godot(&self) -> <RawPtr<P> as GodotConvert>::Via

Converts this type to Godot representation, optimizing for zero-copy when possible. Read more
§

fn to_godot_owned(&self) -> Self::Via
where Self::Via: Clone,

Converts this type to owned Godot representation. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl<P> Copy for RawPtr<P>
where P: Copy + FfiRawPointer,

§

impl<P> Eq for RawPtr<P>
where P: Eq + FfiRawPointer,

§

impl<P> GodotType for RawPtr<P>
where P: FfiRawPointer + 'static,

§

impl<P> StructuralPartialEq for RawPtr<P>
where P: FfiRawPointer,

Auto Trait Implementations§

§

impl<P> Freeze for RawPtr<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for RawPtr<P>
where P: RefUnwindSafe,

§

impl<P> Send for RawPtr<P>
where P: Send,

§

impl<P> Sync for RawPtr<P>
where P: Sync,

§

impl<P> Unpin for RawPtr<P>
where P: Unpin,

§

impl<P> UnwindSafe for RawPtr<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsArg<T> for T
where T: ToGodot<Pass = ByValue>,

§

fn into_arg<'arg>(self) -> CowArg<'arg, T>
where T: 'arg,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.