From 59171e705ba28e1d6513fb1ad6c88fc8d041f8c3 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Tue, 2 Feb 2021 09:47:14 +0100 Subject: [PATCH] Move push macro to seperate module --- src/macros.rs | 24 ++++++++++++++++++++++++ src/main.rs | 3 +++ src/meson.build | 1 + src/widgets/new_navigator.rs | 25 ------------------------- 4 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 src/macros.rs diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..04ea01f --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,24 @@ +/// Simplification for pushing new screens. +/// +/// This macro can be invoked in two forms. +/// +/// 1. To push screens without an input value: +/// +/// ``` +/// let result = push!(handle, ScreenType).await; +/// ``` +/// +/// 2. To push screens with an input value: +/// +/// ``` +/// let result = push!(handle, ScreenType, input).await; +/// ``` +#[macro_export] +macro_rules! push { + ($handle:expr, $screen:ty) => { + $handle.push::<_, _, $screen>(()) + }; + ($handle:expr, $screen:ty, $input:ident) => { + $handle.push::<_, _, $screen>($input) + }; +} diff --git a/src/main.rs b/src/main.rs index 4d1d79d..b17ca7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,9 @@ use glib::clone; use std::cell::RefCell; use std::rc::Rc; +#[macro_use] +mod macros; + mod backend; mod config; mod database; diff --git a/src/meson.build b/src/meson.build index 6667975..bba9fa8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -106,6 +106,7 @@ sources = files( 'widgets/section.rs', 'config.rs', 'config.rs.in', + 'macros.rs', 'main.rs', 'player.rs', 'resources.rs', diff --git a/src/widgets/new_navigator.rs b/src/widgets/new_navigator.rs index 49ca513..8cf0d15 100644 --- a/src/widgets/new_navigator.rs +++ b/src/widgets/new_navigator.rs @@ -6,31 +6,6 @@ use gtk::prelude::*; use std::cell::{Cell, RefCell}; use std::rc::{Rc, Weak}; -/// Simplification for pushing new screens. -/// -/// This macro can be invoked in two forms. -/// -/// 1. To push screens without an input value: -/// -/// ``` -/// let result = push!(handle, ScreenType).await; -/// ``` -/// -/// 2. To push screens with an input value: -/// -/// ``` -/// let result = push!(handle, ScreenType, input).await; -/// ``` -#[macro_export] -macro_rules! push { - ($handle:expr, $screen:ty) => { - $handle.push::<_, _, $screen>(()) - }; - ($handle:expr, $screen:ty, $input:ident) => { - $handle.push::<_, _, $screen>($input) - }; -} - /// A widget that represents a logical unit of transient user interaction and /// that optionally resolves to a specific return value. pub trait Screen: Widget {