1 // Copyright © 2024 Collabora, Ltd. 2 // SPDX-License-Identifier: MIT 3 4 use std::ops::Index; 5 6 pub enum AttrList<T: 'static> { 7 Array(&'static [T]), 8 Uniform(T), 9 } 10 11 impl<T: 'static> Index<usize> for AttrList<T> { 12 type Output = T; 13 index(&self, idx: usize) -> &T14 fn index(&self, idx: usize) -> &T { 15 match self { 16 AttrList::Array(arr) => &arr[idx], 17 AttrList::Uniform(typ) => typ, 18 } 19 } 20 } 21 22 pub trait AsSlice<T> { 23 type Attr; 24 as_slice(&self) -> &[T]25 fn as_slice(&self) -> &[T]; as_mut_slice(&mut self) -> &mut [T]26 fn as_mut_slice(&mut self) -> &mut [T]; attrs(&self) -> AttrList<Self::Attr>27 fn attrs(&self) -> AttrList<Self::Attr>; 28 } 29