Allow any expression blocks in thread_local!
This commit is contained in:
parent
867d39cdf6
commit
fc75a4e146
@ -166,7 +166,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
/// ```
|
/// ```
|
||||||
/// use std::cell::Cell;
|
/// use std::cell::Cell;
|
||||||
/// thread_local! {
|
/// thread_local! {
|
||||||
/// pub static FOO: Cell<u32> = const { Cell::new(1) };
|
/// pub static FOO: Cell<u32> = const {
|
||||||
|
/// let value = 1;
|
||||||
|
/// Cell::new(value)
|
||||||
|
/// };
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// assert_eq!(FOO.get(), 1);
|
/// assert_eq!(FOO.get(), 1);
|
||||||
@ -186,12 +189,12 @@ macro_rules! thread_local {
|
|||||||
// empty (base case for the recursion)
|
// empty (base case for the recursion)
|
||||||
() => {};
|
() => {};
|
||||||
|
|
||||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }; $($rest:tt)*) => (
|
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block; $($rest:tt)*) => (
|
||||||
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
|
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
|
||||||
$crate::thread_local!($($rest)*);
|
$crate::thread_local!($($rest)*);
|
||||||
);
|
);
|
||||||
|
|
||||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }) => (
|
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block) => (
|
||||||
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
|
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user