pub trait KeyValue:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn mangled() -> &'static str;
fn metadata() -> *const c_void;
unsafe fn write(&self, out: *mut u8);
unsafe fn read(from: *const u8) -> Self;
}Expand description
A Swift type a synthesised key can hold.
The three keyed bags — EnvironmentKey, FocusedValueKey,
ContainerValueKey — are generic over their value, and so are these. Each
implementation is four things: the type’s mangled name (for the key path’s
value type), its metadata (for the conformance’s associated type), and the
two directions of moving a value across.
§Ownership
write produces a +1 value, because that is what every use here needs: an
@in argument is owned by the callee, and a defaultValue witness is
called again each time SwiftUI wants the default and destroys what it got. A
String that handed back the same object twice without retaining would be
over-released, which is why the default is kept as a closure that writes a
fresh one rather than as bytes to copy.
read copies and takes nothing: it is reading a value somebody else owns.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".