Skip to main content

generate_sidecar_rust_accessors

Function generate_sidecar_rust_accessors 

Source
fn generate_sidecar_rust_accessors(
    input: &DeriveInput,
    info: &SidecarInfo,
    rebuilds: bool,
) -> TokenStream
Expand description

Generate the Rust accessors of each Sidecar<T> field, as associated functions of the struct taking an owner handle, with the field’s visibility: fn keys(ptr: &impl SidecarOwner<Self>) -> T for #[r_data(ref)], fn set_keys(ptr: &mut impl SidecarOwnerMut<Self>, value: T) for #[r_data(mut)], both for #[r_data(ref, mut)] or a bare #[r_data]. The struct holds no reference to its pointer, so there is no accessor on &self (#1856).

A type with a rebuild hook (rebuilds) also gets fn try_keys(saved: &Saved<'_, Self>) -> Option<T> for every Sidecar field: None when the save has no slot for it (#2187).

A non-pub accessor is #[allow(dead_code)]: it is generated whether or not the crate calls it. The accessors (and the TypedExternal hook) read the fields, so rustc sees them used.