1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
/// Converts a string representation of a number to an equivalent integer number
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: Integer = parse_int!("31337");
/// }
/// ```
#[macro_export]
macro_rules! parse_int {
($value:expr) => {{
let (error, result) = wevm::v0::bindings::parse_int($value.as_ptr(), $value.len());
error!(error);
result
}};
}
/// Converts a string representation of a boolean to an equivalent logical value
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: Boolean = parse_bool!("true");
/// }
/// ```
#[macro_export]
macro_rules! parse_bool {
($value:expr) => {{
let (error, result) = wevm::v0::bindings::parse_bool($value.as_ptr(), $value.len());
error!(error);
result
}};
}
/// Converts an integer to a byte array
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: Binary = to_bytes!(31337);
/// }
/// ```
#[macro_export]
macro_rules! to_bytes {
($value:expr) => {{
let (error, ptr, len) = wevm::v0::bindings::to_bytes($value);
error!(error);
core::slice::from_raw_parts(ptr, len)
}};
}
/// Converts a byte array to an integer number
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let binary: Binary = to_bytes!(31337);
/// let result: Integer = to_int!(binary);
/// }
/// ```
#[macro_export]
macro_rules! to_int {
($value:expr) => {{
let (error, result) = wevm::v0::bindings::to_int($value.as_ptr(), $value.len());
error!(error);
result
}};
}
/// Converts a logical value to a string
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: String = to_string_bool!(true);
/// }
/// ```
#[macro_export]
macro_rules! to_string_bool {
($value:expr) => {{
let (error, ptr, len) = wevm::v0::bindings::to_string_bool($value);
error!(error);
let bytes = core::slice::from_raw_parts(ptr, len);
core::str::from_utf8_unchecked(bytes)
}};
}
/// Converts an integer to a string
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: String = to_string_int!(31337);
/// }
/// ```
#[macro_export]
macro_rules! to_string_int {
($value:expr) => {{
let (error, ptr, len) = wevm::v0::bindings::to_string_int($value);
error!(error);
let bytes = core::slice::from_raw_parts(ptr, len);
core::str::from_utf8_unchecked(bytes)
}};
}
/// Converts an binary to a string
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
/// let result: String = to_string_binary!(&[0, 1]);
/// }
/// ```
#[macro_export]
macro_rules! to_string_binary {
($value:expr) => {{
core::str::from_utf8_unchecked($value)
}};
}