wedpr_l_macros/
lib.rs

1// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2
3//! Library of shared macros.
4
5/// Global flag of enabling debug output.
6pub const ENABLE_DEBUG_OUTPUT: bool = true;
7
8/// Prints debug output that can be disabled by setting a global flag.
9#[macro_export]
10macro_rules! wedpr_println {
11            () => ( print!("\n"));
12            ($($arg:tt)*) => {
13            if $crate::ENABLE_DEBUG_OUTPUT {
14                      print!("{}:{}: ", file!(), line!());
15                      println!($($arg)*);
16            }
17     };
18}
19
20/// Macros to handle errors and return bool type instead of Result type, which
21/// are mainly used to simplify type conversions for Rust FFI.
22
23/// Converts a string to a point if succeeded, otherwise returns false.
24#[macro_export]
25macro_rules! bytes_to_point {
26    ($param:expr) => {
27        match bytes_to_point($param) {
28            Ok(v) => v,
29            Err(_) => {
30                wedpr_println!("macro string_to_point failed");
31                return false;
32            },
33        }
34    };
35}
36
37/// Converts a string to a scalar if succeeded, otherwise returns false.
38#[macro_export]
39macro_rules! bytes_to_scalar {
40    ($param:expr) => {
41        match bytes_to_scalar($param) {
42            Ok(v) => v,
43            Err(_) => {
44                wedpr_println!("macro string_to_scalar failed");
45                return false;
46            },
47        }
48    };
49}