diff --git a/gdnative-core/src/nativescript/macros.rs b/gdnative-core/src/nativescript/macros.rs index e452c77ab..50422970c 100644 --- a/gdnative-core/src/nativescript/macros.rs +++ b/gdnative-core/src/nativescript/macros.rs @@ -321,28 +321,3 @@ macro_rules! godot_wrap_method { ) }; } - -/// Convenience macro to create a profiling signature with a given tag. -/// -/// The expanded code will panic at runtime if the file name or `tag` contains `::` or -/// any NUL-bytes. -/// -/// See `nativescript::profiling::Signature` for more information. -/// -/// # Examples -/// -/// ```rust -/// # fn main() { -/// use gdnative_core::profile_sig; -/// use gdnative_core::nativescript::profiler::profile; -/// -/// let answer = profile(profile_sig!("foo"), || 42); -/// assert_eq!(42, answer); -/// # } -/// ``` -#[macro_export] -macro_rules! profile_sig { - ($tag:expr) => { - $crate::nativescript::profiling::Signature::new(file!(), line!(), $tag) - }; -} diff --git a/gdnative-core/src/nativescript/profiler.rs b/gdnative-core/src/nativescript/profiler.rs index 110a745a6..9f35dc47e 100644 --- a/gdnative-core/src/nativescript/profiler.rs +++ b/gdnative-core/src/nativescript/profiler.rs @@ -13,9 +13,9 @@ use crate::private::try_get_api; /// identifier of the code, usually be the name of the method. None of the substrings should /// contain `::`. /// -/// To create a `Signature` in the correct form, see `Signature::new` or `profile_sig!`. To -/// create a `Signature` from an existing `CStr` or `CString`, see `Signature::from_raw` and -/// `Signature::from_raw_owned`. +/// To create a `Signature` in the correct form, see [`Signature::new()`] or [`profile_sig!`]. To +/// create a `Signature` from an existing `CStr` or `CString`, see [`Signature::from_raw()`] and +/// [`Signature::from_raw_owned()`]. #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct Signature<'a> { sig: Cow<'a, CStr>, @@ -54,7 +54,7 @@ impl<'a> Signature<'a> { Self::from_raw(sig) } - /// Create a borrowed version of `self` for repeated use with `add_data` or `profile`. + /// Create a borrowed version of `self` for repeated use with [`add_data()`][Self::add_data()] or [`profile()`][Self::add_data()]. #[inline(always)] pub fn borrow(&self) -> Signature<'_> { Signature { @@ -64,7 +64,7 @@ impl<'a> Signature<'a> { /// Add a data point to Godot's built-in profiler using this signature. /// - /// See the free function `gdnative::nativescript::profiling::add_data`. + /// See the free function [`profiler::add_data()`][add_data()]. #[inline] pub fn add_data(&self, time: Duration) { add_data(self.borrow(), time) @@ -73,7 +73,7 @@ impl<'a> Signature<'a> { /// Times a closure and adds the measured time to Godot's built-in profiler with this /// signature, and then returns it's return value. /// - /// See the free function `gdnative::nativescript::profiling::profile`. + /// See the free function [`profiler::profile()`][profile()]. #[inline] pub fn profile(&self, f: F) -> R where @@ -155,3 +155,30 @@ where add_data(signature, Instant::now() - start); ret } + +/// Convenience macro to create a profiling signature with a given tag. +/// +/// The expanded code will panic at runtime if the file name or `tag` contains `::` or +/// any NUL-bytes. +/// +/// See [`Signature`] for more information. +/// +/// # Examples +/// +/// ```rust +/// # fn main() { +/// use gdnative::nativescript::profiler::{profile, profile_sig}; +/// +/// let answer = profile(profile_sig!("foo"), || 42); +/// assert_eq!(answer, 42); +/// # } +/// ``` +#[macro_export] +macro_rules! _profile_sig { + ($tag:expr) => { + $crate::nativescript::profiler::Signature::new(file!(), line!(), $tag) + }; +} + +// Export macro in this module +pub use _profile_sig as profile_sig; diff --git a/gdnative-derive/src/profiled.rs b/gdnative-derive/src/profiled.rs index e38414f0d..5f6f9bd99 100644 --- a/gdnative-derive/src/profiled.rs +++ b/gdnative-derive/src/profiled.rs @@ -111,7 +111,8 @@ pub(crate) fn derive_profiled( let stmts = std::mem::take(&mut item_fn.block.stmts); item_fn.block = Box::new(parse_quote!({ - ::gdnative::nativescript::profiling::profile(::gdnative::profile_sig!(#tag), move || { + ::gdnative::nativescript::profiler::profile( + ::gdnative::nativescript::profiler::profile_sig!(#tag), move || { #(#stmts)* }) })); diff --git a/gdnative/src/lib.rs b/gdnative/src/lib.rs index 61fbd0d3e..d5a50532c 100644 --- a/gdnative/src/lib.rs +++ b/gdnative/src/lib.rs @@ -58,9 +58,14 @@ // Items, which are #[doc(hidden)] in their original crate and re-exported with a wildcard, lose // their hidden status. Re-exporting them manually and hiding the wildcard solves this. #[doc(inline)] +pub use gdnative_core::{core_types, nativescript, object}; + +// Make macros available inside crate on top-level, for convenience and to make other macros look nicer +// For the user, they are exported either in prelude (convenience) or fully qualified. +#[deprecated] pub use gdnative_core::{ - core_types, godot_dbg, godot_error, godot_gdnative_init, godot_gdnative_terminate, godot_init, - godot_nativescript_init, godot_print, godot_warn, godot_wrap_method, nativescript, object, + godot_dbg, godot_error, godot_gdnative_init, godot_gdnative_terminate, godot_init, + godot_nativescript_init, godot_print, godot_warn, godot_wrap_method, }; #[doc(hidden)]