amplify/
macro_default.rs

1// Rust language amplification library providing multiple generic trait
2// implementations, type wrappers, derive macros and other language enhancements
3//
4// Written in 2019-2020 by
5//     Dr. Maxim Orlovsky <orlovsky@ubideco.org>
6//     Martin Habovstiak <martin.habovstiak@gmail.com>
7//
8// To the extent possible under law, the author(s) have dedicated all
9// copyright and related and neighboring rights to this software to
10// the public domain worldwide. This software is distributed without
11// any warranty.
12//
13// You should have received a copy of the MIT License
14// along with this software.
15// If not, see <https://opensource.org/licenses/MIT>.
16
17/// Macro for quick & simple `&str` -> `String` conversion:
18/// ```
19/// #[macro_use]
20/// extern crate amplify;
21///
22/// # fn main() {
23/// enum Error {
24///     Io(String),
25/// }
26///
27/// impl From<std::io::Error> for Error {
28///     fn from(err: std::io::Error) -> Error {
29///         Self::Io(s!("I/O error"))
30///     }
31/// }
32/// # }
33/// ```
34#[macro_export]
35macro_rules! s {
36    ( $str:literal ) => {
37        String::from($str)
38    };
39}
40
41/// This macro allows more semantically-clear code (which can be used especially
42/// with structure initialization), indicating that instead of type value we are
43/// generating no value at all (empty collection or data structure filled with
44/// information indicating absence of data)
45#[macro_export]
46macro_rules! none {
47    () => {
48        Default::default()
49    };
50}
51
52/// This macro allows more semantically-clear code (which can be used especially
53/// with structure initialization), indicating that instead of type value we are
54/// generating zero values (int types or byte slices filled with zeros)
55#[macro_export]
56macro_rules! zero {
57    () => {
58        Default::default()
59    };
60}
61
62/// This macro allows more semantically-clear code (which can be used especially
63/// with structure initialization), indicating that instead of type value we are
64/// generating empty collection types
65#[macro_export]
66macro_rules! empty {
67    () => {
68        Default::default()
69    };
70}
71
72/// Shorthand for `Default::default()`
73#[macro_export]
74macro_rules! default {
75    () => {
76        Default::default()
77    };
78}
79
80/// Shorthand for `Dumb::dumb()`
81#[macro_export]
82macro_rules! dumb {
83    () => {
84        $crate::Dumb::dumb()
85    };
86}