pub trait Global: 'static { }Expand description
A marker trait for types that can be stored in GPUI’s global state.
This trait exists to provide type-safe access to globals by ensuring only
types that implement Global can be used with the accessor methods. For
example, trying to access a global with a type that does not implement
Global will result in a compile-time error.
Implement this on types you want to store in the context as a global.
§Restricting Access to Globals
In some situations you may need to store some global state, but want to restrict access to reading it or writing to it.
In these cases, Rust’s visibility system can be used to restrict access to
a global value. For example, you can create a private struct that implements
Global and holds the global state. Then create a newtype struct that wraps
the global type and create custom accessor methods to expose the desired subset
of operations.