mesa/src/compiler/rust/as_slice.rs
Faith Ekstrand ab72be6c5e nak,compiler: Move AsSlice to common code
Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30443>
2024-08-07 21:08:19 +00:00

28 lines
570 B
Rust

// Copyright © 2024 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use std::ops::Index;
pub enum AttrList<T: 'static> {
Array(&'static [T]),
Uniform(T),
}
impl<T: 'static> Index<usize> for AttrList<T> {
type Output = T;
fn index(&self, idx: usize) -> &T {
match self {
AttrList::Array(arr) => &arr[idx],
AttrList::Uniform(typ) => typ,
}
}
}
pub trait AsSlice<T> {
type Attr;
fn as_slice(&self) -> &[T];
fn as_mut_slice(&mut self) -> &mut [T];
fn attrs(&self) -> AttrList<Self::Attr>;
}