Skip to content

Commit f17b370

Browse files
committed
Hack macro-scoping into crate::signal for get_window
Utilise `#[doc(inline)]` and `#[doc(never)]` to hide name from crate root and show up in `::signal` namespace instead.
1 parent ab8e89f commit f17b370

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

sci-rs/src/signal/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ pub mod convolve;
2424
/// namespace is located here.
2525
pub mod windows;
2626

27+
// Convenience macro for down-stream users
28+
/// This provides the same convenience function as in the scipy.signal namespace. Returns a window
29+
/// of given length and type.
30+
///
31+
/// # Parameters:
32+
/// - `window`: The type of window to create.
33+
/// - `m`: Number of samples in the window.
34+
/// - `fftbins`: If true (default), creates a "periodic" window, ready to use with ifftshift and be
35+
/// multiplied by the result of an FFT. If False, create a "symmetric" window, for use in filter design.
36+
#[doc(inline)]
37+
pub use crate::_signal_windows_getWindow as get_window;
38+
2739
/// Signal Resampling
2840
/// This contains only the
2941
/// [`resample`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.resample.html#scipy.signal.resample)

sci-rs/src/signal/windows/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,16 @@ where
338338
/// of given length and type.
339339
///
340340
/// # Parameters:
341-
/// - window: The type of window to create.
342-
/// - m: Number of samples in the window.
343-
/// - fftbins: If true (default), creates a "periodic" window, ready to use with ifftshift and be
341+
/// - `window`: The type of window to create.
342+
/// - `m`: Number of samples in the window.
343+
/// - `fftbins`: If true (default), creates a "periodic" window, ready to use with ifftshift and be
344344
/// multiplied by the result of an FFT. If False, create a "symmetric" window, for use in filter design.
345345
// #[cfg(feature = "std")]
346+
/// Documentation is provided only at the public point of the interface. It is mangled here to
347+
/// provide scoping.
348+
#[doc(hidden)]
346349
#[macro_export]
347-
macro_rules! get_window {
350+
macro_rules! _signal_windows_getWindow {
348351
// Parameterized windows (tuple form with sym)
349352
( ("kaiser", $beta:expr), $m:expr, $sym:expr ) => {
350353
$crate::signal::windows::Kaiser::new($m, $beta, !$sym).get_window()

sci-rs/src/signal/windows/triangle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where
6666
/// (`std` feature is required for macros.)
6767
/// #[cfg(feature = "std")]
6868
/// ```
69-
/// use sci_rs::get_window;
69+
/// use sci_rs::signal::get_window;
7070
/// use sci_rs::signal::windows::GetWindow;
7171
/// let actual = get_window!("triangle", 8);
7272
/// assert_eq!(vec![0.125, 0.375, 0.625, 0.875, 0.875, 0.625, 0.375, 0.125], actual);
@@ -209,7 +209,7 @@ mod tests {
209209
#[test]
210210
#[cfg(feature = "std")]
211211
fn from_macro() {
212-
use crate::get_window;
212+
use crate::signal::get_window;
213213

214214
let actual = get_window!("triangle", 8);
215215
assert_eq!(

0 commit comments

Comments
 (0)