pub trait StoredValue:
Clone
+ Send
+ 'static {
// Required methods
fn metadata() -> *const c_void;
fn field_type() -> &'static [u8] ⓘ;
fn mangled() -> &'static str;
fn buffer_bytes() -> usize;
unsafe fn init_storage(&self, key: &str) -> u64;
unsafe fn decode(buf: &[u8]) -> Self;
fn encode(&self) -> Vec<u8> ⓘ;
}Expand description
A type @AppStorage can hold.
The four AppStorage takes without a RawRepresentable detour. The
accessors are generic over Value and so are shared — only the initialiser
differs per type, and it differs in ways worth having read rather than
guessed. From swiftc -emit-ir:
AppStorage<Bool>.init (i1, i64, ptr, i64) ; x0=value, x1/x2=key, x3=store
AppStorage<Int>.init (i64, i64, ptr, i64) ; x0=value, x1/x2=key, x3=store
AppStorage<Double>.init (double, i64, ptr, i64) ; d0=value, x0/x1=key, x2=store
AppStorage<String>.init (i64, ptr, i64, ptr, i64) ; x0/x1=value, x2/x3=key, x4=storeDouble is the one that breaks the pattern: its value travels in a float
register, so the key and the store shift down one.
Required Methods§
Sourcefn metadata() -> *const c_void
fn metadata() -> *const c_void
Value.Type — what the accessors want in x1, not AppStorage<Value>’s.
Sourcefn field_type() -> &'static [u8] ⓘ
fn field_type() -> &'static [u8] ⓘ
The mangled AppStorage<Self>, NUL-terminated, for the field record.
Sourcefn buffer_bytes() -> usize
fn buffer_bytes() -> usize
How many bytes the accessors read and write.
Sourceunsafe fn init_storage(&self, key: &str) -> u64
unsafe fn init_storage(&self, key: &str) -> u64
Build the wrapper, returning its UserDefaultLocation.
§Safety
Calls into SwiftUI; key must be a valid string.
Sourceunsafe fn decode(buf: &[u8]) -> Self
unsafe fn decode(buf: &[u8]) -> Self
Read Self out of an accessor’s @out buffer, consuming whatever the
getter handed over.
§Safety
buf must be exactly buffer_bytes of a valid
Self, owned at +1.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".