Skip to content

Commit

Permalink
Smaller fixes for clippy and doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Feb 4, 2023
1 parent bcad368 commit 5ea5447
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions godot-core/src/builtin/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ impl Share for Dictionary {
///
/// Example
/// ```no_run
/// use godot::builtin::dict;
/// use godot::builtin::{dict, Variant};
///
/// let key = "my_key";
/// let d = dict! {
/// "key1": 10,
/// "another": Variant::nil(),
/// key: true,
/// (1 + 2): "final",
/// }
/// };
/// ```
#[macro_export]
macro_rules! dict {
Expand Down
18 changes: 16 additions & 2 deletions godot-ffi/src/godot_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ use crate as sys;
use std::fmt::Debug;

/// Adds methods to convert from and to Godot FFI pointers.
#[doc(hidden)]
/// See [crate::ffi_methods] for ergonomic implementation.
pub trait GodotFfi {
/// Construct from Godot opaque pointer.
///
/// # Safety
/// `ptr` must be a valid _type ptr_: it must follow Godot's convention to encode `Self`,
/// which is different depending on the type.
unsafe fn from_sys(ptr: sys::GDExtensionTypePtr) -> Self;

/// Construct uninitialized opaque data, then initialize it with `init` function.
/// Construct uninitialized opaque data, then initialize it with `init_fn` function.
///
/// # Safety
/// `init_fn` must be a function that correctly handles a (possibly-uninitialized) _type ptr_.
unsafe fn from_sys_init(init_fn: impl FnOnce(sys::GDExtensionTypePtr)) -> Self;

/// Return Godot opaque pointer, for an immutable operation.
Expand All @@ -38,6 +45,11 @@ pub trait GodotFfi {
self.sys()
}

/// Write the contents of `self` into the pointer `dst`.
///
/// # Safety
/// `dst` must be a valid _type ptr_: it must follow Godot's convention to encode `Self`,
/// which is different depending on the type.
unsafe fn write_sys(&self, dst: sys::GDExtensionTypePtr);
}

Expand Down Expand Up @@ -66,6 +78,7 @@ pub trait GodotFuncMarshal: Sized {
// See doc comment of `ffi_methods!` for information

#[macro_export]
#[doc(hidden)]
macro_rules! ffi_methods_one {
// type $Ptr = *mut Opaque
(OpaquePtr $Ptr:ty; $( #[$attr:meta] )? $vis:vis $from_sys:ident = from_sys) => {
Expand Down Expand Up @@ -159,6 +172,7 @@ macro_rules! ffi_methods_one {
}

#[macro_export]
#[doc(hidden)]
macro_rules! ffi_methods_rest {
( // impl T: each method has a custom name and is annotated with 'pub'
$Impl:ident $Ptr:ty; $( fn $user_fn:ident = $sys_fn:ident; )*
Expand Down
1 change: 1 addition & 0 deletions godot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub use godot_core::private;
/// Often-imported symbols.
pub mod prelude {
pub use super::bind::{godot_api, GodotClass, GodotExt};
pub use super::builtin::dict; // Re-export macros.
pub use super::builtin::*;
pub use super::engine::{
load, try_load, utilities, AudioStreamPlayer, Camera2D, Camera3D, Input, Node, Node2D,
Expand Down

0 comments on commit 5ea5447

Please sign in to comment.