Skip to content

Instantly share code, notes, and snippets.

@XavilPergis
Created December 1, 2018 07:21
Show Gist options
  • Save XavilPergis/60fba30039bcc3b95f5481679d46fe90 to your computer and use it in GitHub Desktop.
Save XavilPergis/60fba30039bcc3b95f5481679d46fe90 to your computer and use it in GitHub Desktop.
macro_rules! attr_tuple {
($($ty:ident: $field:tt),*) => {
unsafe impl<$($ty),*> InterleavedAttribute for ($($ty),*) where $($ty: InterleavedAttribute),* {
fn attribute_format<Func>(mut func: Func)
where
Func: FnMut(AttributeFormat),
{
let stride = mem::size_of::<Self>();
$(
let offset = offset_of!(Self, $field);
$ty::attribute_format(|attr| func(attr.resize(stride, offset)));
)*
}
}
};
}
attr_tuple![A:0, B:1];
attr_tuple![A:0, B:1, C:2];
attr_tuple![A:0, B:1, C:2, D:3];
attr_tuple![A:0, B:1, C:2, D:3, E:4];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21, W:22];
attr_tuple![A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21, W:22, X:23];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment