Move push macro to seperate module

This commit is contained in:
Elias Projahn 2021-02-02 09:47:14 +01:00
parent 06d181447c
commit 59171e705b
4 changed files with 28 additions and 25 deletions

24
src/macros.rs Normal file
View file

@ -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)
};
}

View file

@ -11,6 +11,9 @@ use glib::clone;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
#[macro_use]
mod macros;
mod backend; mod backend;
mod config; mod config;
mod database; mod database;

View file

@ -106,6 +106,7 @@ sources = files(
'widgets/section.rs', 'widgets/section.rs',
'config.rs', 'config.rs',
'config.rs.in', 'config.rs.in',
'macros.rs',
'main.rs', 'main.rs',
'player.rs', 'player.rs',
'resources.rs', 'resources.rs',

View file

@ -6,31 +6,6 @@ use gtk::prelude::*;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::rc::{Rc, Weak}; 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 /// A widget that represents a logical unit of transient user interaction and
/// that optionally resolves to a specific return value. /// that optionally resolves to a specific return value.
pub trait Screen<I, O>: Widget { pub trait Screen<I, O>: Widget {