Inner Workings
As it was mentioned in the Basics, fieldx
rewrites structures with fxstruct
applied. The
following table reveals the final types of fields. T
in the table represents the original field type, as specified
by the user; O
is the original struct type.
Field Parameters | Plain Type | Sync Type | Async Type |
---|---|---|---|
inner_mut | RefCell<T> | sync::FXRwLock<T> or parking_lot::RwLock | async::FXRwLock<T> , or tokio::sync::RwLock or async_lock::RwLock |
lazy | once_cell::unsync::OnceCell<T> | once_cell::sync::OnceCell<T> | tokio::sync::OnceCell<T> or async_lock::OnceCell<T> |
lazy + lock | N/A | sync::FXProxy<O, T> | async::FXProxy<O,T> |
optional (also activated with clearer and predicate ) | Option<T> | sync::FXRwLock<Option<T>> | async::FXRwLock<Option<T>> |
lock , reader and/or writer | N/A | sync::FXRwLock<T> | async::FXRwLock<T> |
The way a particular container type is chosen depends on the combination of the enabled feature flags. With regard to the async mode operation refer to the Async Mode of Operation chapter, Backend Choice section for more details. With regard to the choice between FXRwLock
and RwLock
see the More on Locks chapter.
Apparently, skipped fields retain their original type. Sure enough, if such a field is of non-Send
or non-Sync
type the entire struct would be missing these traits despite all the efforts from the fxstruct
macro.
There is also a difference in how the initialization of lazy
fields is implemented. For non-locked (simple) fields
the lazy builder method is called directly from the accessor method. For locked fields, however, the lazy
builder is invoked by the implementation of the proxy type.