|
16 | 16 | // under the License.
|
17 | 17 |
|
18 | 18 | use crate::types::{LogicalTypeRef, NativeType};
|
19 |
| -use std::sync::{Arc, LazyLock}; |
| 19 | +use std::sync::{Arc, OnceLock}; |
20 | 20 |
|
21 | 21 | macro_rules! singleton {
|
22 |
| - ($name:ident, $ty:ident) => { |
23 |
| - #[doc = concat!("Singleton instance of a logical type representing [`NativeType::", stringify!($ty), "`].")] |
24 |
| - pub static $name: LazyLock<LogicalTypeRef> = |
25 |
| - LazyLock::new(|| Arc::new(NativeType::$ty)); |
| 22 | + ($name:ident, $getter:ident, $ty:ident) => { |
| 23 | + // TODO: Use LazyLock instead of getter function when MSRV gets bumped |
| 24 | + static $name: OnceLock<LogicalTypeRef> = OnceLock::new(); |
| 25 | + |
| 26 | + #[doc = "Getter for singleton instance of a logical type representing"] |
| 27 | + #[doc = concat!("[`NativeType::", stringify!($ty), "`].")] |
| 28 | + pub fn $getter() -> LogicalTypeRef { |
| 29 | + $name.get_or_init(|| Arc::new(NativeType::$ty)) |
| 30 | + } |
26 | 31 | };
|
27 | 32 | }
|
28 | 33 |
|
29 |
| -singleton!(LOGICAL_NULL, Null); |
30 |
| -singleton!(LOGICAL_BOOLEAN, Boolean); |
31 |
| -singleton!(LOGICAL_INT8, Int8); |
32 |
| -singleton!(LOGICAL_INT16, Int16); |
33 |
| -singleton!(LOGICAL_INT32, Int32); |
34 |
| -singleton!(LOGICAL_INT64, Int64); |
35 |
| -singleton!(LOGICAL_UINT8, UInt8); |
36 |
| -singleton!(LOGICAL_UINT16, UInt16); |
37 |
| -singleton!(LOGICAL_UINT32, UInt32); |
38 |
| -singleton!(LOGICAL_UINT64, UInt64); |
39 |
| -singleton!(LOGICAL_FLOAT16, Float16); |
40 |
| -singleton!(LOGICAL_FLOAT32, Float32); |
41 |
| -singleton!(LOGICAL_FLOAT64, Float64); |
42 |
| -singleton!(LOGICAL_DATE, Date); |
43 |
| -singleton!(LOGICAL_BINARY, Binary); |
44 |
| -singleton!(LOGICAL_STRING, String); |
| 34 | +singleton!(LOGICAL_NULL, logical_null, Null); |
| 35 | +singleton!(LOGICAL_BOOLEAN, logical_boolean, Boolean); |
| 36 | +singleton!(LOGICAL_INT8, logical_int8, Int8); |
| 37 | +singleton!(LOGICAL_INT16, logical_int16, Int16); |
| 38 | +singleton!(LOGICAL_INT32, logical_int32, Int32); |
| 39 | +singleton!(LOGICAL_INT64, logical_int64, Int64); |
| 40 | +singleton!(LOGICAL_UINT8, logical_uint8, UInt8); |
| 41 | +singleton!(LOGICAL_UINT16, logical_uint16, UInt16); |
| 42 | +singleton!(LOGICAL_UINT32, logical_uint32, UInt32); |
| 43 | +singleton!(LOGICAL_UINT64, logical_uint64, UInt64); |
| 44 | +singleton!(LOGICAL_FLOAT16, logical_float16, Float16); |
| 45 | +singleton!(LOGICAL_FLOAT32, logical_float32, Float32); |
| 46 | +singleton!(LOGICAL_FLOAT64, logical_float64, Float64); |
| 47 | +singleton!(LOGICAL_DATE, logical_date, Date); |
| 48 | +singleton!(LOGICAL_BINARY, logical_binary, Binary); |
| 49 | +singleton!(LOGICAL_STRING, logical_string, String); |
0 commit comments