Function bevy::core::cast_slice

source ·
pub fn cast_slice<A, B>(a: &[A]) -> &[B]
where A: NoUninit, B: AnyBitPattern,
Expand description

Cast &[A] into &[B].

§Panics

This is try_cast_slice but will panic on error.

Examples found in repository?
examples/shader/shader_instancing.rs (line 167)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
fn prepare_instance_buffers(
    mut commands: Commands,
    query: Query<(Entity, &InstanceMaterialData)>,
    render_device: Res<RenderDevice>,
) {
    for (entity, instance_data) in &query {
        let buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
            label: Some("instance data buffer"),
            contents: bytemuck::cast_slice(instance_data.as_slice()),
            usage: BufferUsages::VERTEX | BufferUsages::COPY_DST,
        });
        commands.entity(entity).insert(InstanceBuffer {
            buffer,
            length: instance_data.len(),
        });
    }
}