neptune_common/
warn.rs

1/// This module contains the warn! macro.
2/// The purpose of this macro is to easily pass warnings as wasm attributes.
3/// Additional information is included in the attributes like the function name.
4/// Display must be implemented for the expression passed into warn!.
5/// ```
6/// # use cosmwasm_std::{attr, Response, StdError};
7/// # use neptune_common::warn;
8/// # fn test_warn() -> Result<Response, StdError> {
9/// let mut attrs = vec![warn!("This is a warning")]; // attrs will be populated though Display
10/// let another = "This is another warning";
11/// warn!(attrs, another); // attrs can be pushed with this syntax.
12/// #   Ok(Response::default().add_attributes(attrs))
13/// # }
14/// ```
15#[macro_export]
16macro_rules! warn {
17    ($attrs:ident, $variant:expr) => {{
18        fn f() {}
19        fn type_name_of<T>(_: T) -> &'static str { std::any::type_name::<T>() }
20        let name = type_name_of(f);
21        let msg = format!("{} In function: {}", $variant, &name[..name.len() - 3]);
22        $attrs.push(attr("neptune_warning", msg))
23    }};
24    ($variant:expr) => {{
25        fn f() {}
26        fn type_name_of<T>(_: T) -> &'static str { std::any::type_name::<T>() }
27        let name = type_name_of(f);
28        let msg = format!("{} In function: {}", $variant, &name[..name.len() - 3]);
29        attr("neptune_warning", msg)
30    }};
31}