-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
In #8495 (comment) @Wumpf asked @inner-daemons to pin an ArrayVec because we're going to take a pointer to it, resulting in this code:
let mut view_instancing =
core::pin::pin!(ArrayVec::<Direct3D12::D3D12_VIEW_INSTANCE_LOCATION, 32>::new());However, this doesn't help and isn't necessary.
"Doesn't help": like most types, ArrayVec<T> implements Unpin if T does, meaning that Pin<ArrayVec<T>> is just an ordinary newtype, with no unusual effect. You could simply use Pin::get_mut to get a mutable reference to the ArrayVec and then use std::mem::replace to swap out a different one and drop the original.
"Isn't necessary": You can actually do what you intend here without using pin, using ordinary Rust:
-
Before building the
D3D12_VIEW_INSTANCING_DESC, declare a local variable that borrows a shared reference toview_instancing. -
Use this reference directly to initialize
pViewInstanceLocations, since&Tconverts to*const Tautomatically. -
Say
drop(<reference var>);after you're done using the pointer. This ensures that the shared reference lives this long.
As long as view_instancing is borrowed for sharing, it can't be moved.