I have a RefCell variable STATE inside thread_local! macro which has the type State when I try to deploy and request access to STATE it gives me an error "State Not Initialized". As soon as I commented min_delay it worked fine. I want to know why u64 types cannot be initialized inside RefCell.
The code builds but does not initialize the state, and when trying to access it give an error
To access I used a custom-defined macros function
const __STATE_ALREADY_INITIALIZED: &str = "State has already been initialized";
const __STATE_NOT_INITIALIZED: &str = "State has not been initialized";
fn read_state<F, R>(f: F) -> R
where
F: FnOnce(&$type) -> R,
{
__STATE.with_borrow(|s| f(s.as_ref().expect(__STATE_NOT_INITIALIZED)))
}
I have another crates with same initialize type and that works fine, in this crate I introduced another property min_delay in the HeapStates struct it produces an error
I follow the same pattern for other crates and those are working fine, but this crate gives me an error because of the introduction of the new property min_delay inside HeapStates.
To be 100% clear, I know with certainty that adding u64 to that struct isn't the issue.
It is possible to make compilation fail by adding a field, since auto traits are automatically inherited, but u64 implements all the auto traits, and you described your error as a runtime error, not a compilation error.
It is also uncommon but possible to cause a runtime error by introducing a field, since it changes the result of needs_drop[1], size_of, and derive macros, but these would only happen if code elsewhere is incorrectly written or being misused.
If you have anything time-aware in your code, then that could be the issue, but time-related bugs are rare in single-threaded context.
My best guess is that you made the call to init_state dependent on deserialization succeeding, aren't handling deserialization errors, and have an unconditional call to mutate_state.
Thanks for the explanation. Now I understand the error, In State::Default() I define the Default config function for min_delay, rather than passing constant value I passed the set_min_delay() function which ultimately accesses the HeapState which is not yet initialized