Skip to content

Commit 0264fe8

Browse files
committed
nativescript::profiler module: modernize doc links, export profile_sig!
1 parent 1affee3 commit 0264fe8

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

gdnative-core/src/nativescript/macros.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -321,28 +321,3 @@ macro_rules! godot_wrap_method {
321321
)
322322
};
323323
}
324-
325-
/// Convenience macro to create a profiling signature with a given tag.
326-
///
327-
/// The expanded code will panic at runtime if the file name or `tag` contains `::` or
328-
/// any NUL-bytes.
329-
///
330-
/// See `nativescript::profiling::Signature` for more information.
331-
///
332-
/// # Examples
333-
///
334-
/// ```rust
335-
/// # fn main() {
336-
/// use gdnative_core::profile_sig;
337-
/// use gdnative_core::nativescript::profiler::profile;
338-
///
339-
/// let answer = profile(profile_sig!("foo"), || 42);
340-
/// assert_eq!(42, answer);
341-
/// # }
342-
/// ```
343-
#[macro_export]
344-
macro_rules! profile_sig {
345-
($tag:expr) => {
346-
$crate::nativescript::profiling::Signature::new(file!(), line!(), $tag)
347-
};
348-
}

gdnative-core/src/nativescript/profiler.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use crate::private::try_get_api;
1313
/// identifier of the code, usually be the name of the method. None of the substrings should
1414
/// contain `::`.
1515
///
16-
/// To create a `Signature` in the correct form, see `Signature::new` or `profile_sig!`. To
17-
/// create a `Signature` from an existing `CStr` or `CString`, see `Signature::from_raw` and
18-
/// `Signature::from_raw_owned`.
16+
/// To create a `Signature` in the correct form, see [`Signature::new()`] or [`profile_sig!`]. To
17+
/// create a `Signature` from an existing `CStr` or `CString`, see [`Signature::from_raw()`] and
18+
/// [`Signature::from_raw_owned()`].
1919
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
2020
pub struct Signature<'a> {
2121
sig: Cow<'a, CStr>,
@@ -54,7 +54,7 @@ impl<'a> Signature<'a> {
5454
Self::from_raw(sig)
5555
}
5656

57-
/// Create a borrowed version of `self` for repeated use with `add_data` or `profile`.
57+
/// Create a borrowed version of `self` for repeated use with [`add_data()`][Self::add_data()] or [`profile()`][Self::add_data()].
5858
#[inline(always)]
5959
pub fn borrow(&self) -> Signature<'_> {
6060
Signature {
@@ -64,7 +64,7 @@ impl<'a> Signature<'a> {
6464

6565
/// Add a data point to Godot's built-in profiler using this signature.
6666
///
67-
/// See the free function `gdnative::nativescript::profiling::add_data`.
67+
/// See the free function [`profiler::add_data()`][add_data()].
6868
#[inline]
6969
pub fn add_data(&self, time: Duration) {
7070
add_data(self.borrow(), time)
@@ -73,7 +73,7 @@ impl<'a> Signature<'a> {
7373
/// Times a closure and adds the measured time to Godot's built-in profiler with this
7474
/// signature, and then returns it's return value.
7575
///
76-
/// See the free function `gdnative::nativescript::profiling::profile`.
76+
/// See the free function [`profiler::profile()`][profile()].
7777
#[inline]
7878
pub fn profile<F, R>(&self, f: F) -> R
7979
where
@@ -155,3 +155,30 @@ where
155155
add_data(signature, Instant::now() - start);
156156
ret
157157
}
158+
159+
/// Convenience macro to create a profiling signature with a given tag.
160+
///
161+
/// The expanded code will panic at runtime if the file name or `tag` contains `::` or
162+
/// any NUL-bytes.
163+
///
164+
/// See [`Signature`] for more information.
165+
///
166+
/// # Examples
167+
///
168+
/// ```rust
169+
/// # fn main() {
170+
/// use gdnative::nativescript::profiler::{profile, profile_sig};
171+
///
172+
/// let answer = profile(profile_sig!("foo"), || 42);
173+
/// assert_eq!(answer, 42);
174+
/// # }
175+
/// ```
176+
#[macro_export]
177+
macro_rules! _profile_sig {
178+
($tag:expr) => {
179+
$crate::nativescript::profiler::Signature::new(file!(), line!(), $tag)
180+
};
181+
}
182+
183+
// Export macro in this module
184+
pub use _profile_sig as profile_sig;

gdnative-derive/src/profiled.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ pub(crate) fn derive_profiled(
111111

112112
let stmts = std::mem::take(&mut item_fn.block.stmts);
113113
item_fn.block = Box::new(parse_quote!({
114-
::gdnative::nativescript::profiling::profile(::gdnative::profile_sig!(#tag), move || {
114+
::gdnative::nativescript::profiler::profile(
115+
::gdnative::nativescript::profiler::profile_sig!(#tag), move || {
115116
#(#stmts)*
116117
})
117118
}));

gdnative/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@
5858
// Items, which are #[doc(hidden)] in their original crate and re-exported with a wildcard, lose
5959
// their hidden status. Re-exporting them manually and hiding the wildcard solves this.
6060
#[doc(inline)]
61+
pub use gdnative_core::{core_types, nativescript, object};
62+
63+
// Make macros available inside crate on top-level, for convenience and to make other macros look nicer
64+
// For the user, they are exported either in prelude (convenience) or fully qualified.
65+
#[deprecated]
6166
pub use gdnative_core::{
62-
core_types, godot_dbg, godot_error, godot_gdnative_init, godot_gdnative_terminate, godot_init,
63-
godot_nativescript_init, godot_print, godot_warn, godot_wrap_method, nativescript, object,
67+
godot_dbg, godot_error, godot_gdnative_init, godot_gdnative_terminate, godot_init,
68+
godot_nativescript_init, godot_print, godot_warn, godot_wrap_method,
6469
};
6570

6671
#[doc(hidden)]

0 commit comments

Comments
 (0)