Module data

Module data 

Source
Expand description

Duat’s way of sharing and updating state

This module consists primarily of the RwData struct, which holds state that can be read or written to. When it is modified, other holders of a clone of RwData will know that the data within has been modified.

This is used in many places, for example, Widgets can read from Buffers, and Duat can know when a Buffer has been altered, so these Widgets may be updated automatically.

Another struct from this module is DataMap. This is essentially a mapping for a RwData. It is created via RwData::map, and both it and RwData can be very useful in, for example, a StatusLine, since it will be updated automatically whenever the RwData is altered.

One thing to note is that these structs are only meant to exist and be used in the main thread of execution in Duat. In fact, it should be impossible to acquire them outside of this main thread without use of unsafe code. If it is still possible, report that as a bug.

The reason why these structs should only be valid in the main thread is because, internally, they use non Send/Sync structs, specifically RefCell and UnsafeCell. These are often considered “crutches” by a lot of the Rust community, but in an environment where most of the code is supposed to be able to access most of the state, it is impossible to go without using them.

The use of UnsafeCell internally also makes the read and write operations basically 0 cost,

Structs§

DataMap
A mapping of an RwData
Pass
A key for reading/writing to RwData
PeriodicChecker
A checking struct that periodically returns true
RwData
A container for shared read/write state