Skip to main content

luaur_common/methods/
f_value_t.rs

1//! `FValue<T>::operator T() const` — reads the flag's current value. Reference:
2//! `luau/Common/include/Luau/Common.h` (`LUAU_FORCEINLINE operator T()`).
3//!
4//! Modelled as `get()` rather than a `From`/`Deref` conversion: the value lives
5//! behind `UnsafeCell` (so a `static` flag stays mutable), so it is returned by
6//! copy, not by reference.
7
8use crate::records::f_value::{overrides_active, FValue, FValueOverridable};
9
10impl<T: FValueOverridable> FValue<T> {
11    pub fn get(&self) -> T {
12        // Fast path: no test has ever installed an override -> read the global.
13        // A test that installs a `ScopedFastFlag`/`ScopedFastInt` flips
14        // `OVERRIDES_ACTIVE`, and its per-thread override then shadows the
15        // global for that thread only (so parallel tests don't interfere).
16        if overrides_active() {
17            if let Some(v) = T::override_top(self as *const FValue<T> as usize) {
18                return v;
19            }
20        }
21        unsafe { *self.value.get() }
22    }
23}