Skip to content

Commit b10a37a

Browse files
C3papaxcut
andauthored
Docs: describe how to create multidimensional std::Array (#407)
doc: descirbe how to create multidimensional std::Array Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
1 parent 103d434 commit b10a37a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

includes/std/array.pat

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import std.core;
66
/*!
77
The array library contains a helper type to make it easier to create multi-dimensional arrays
88
and pass arrays to functions as parameters.
9+
10+
## Multi-dimensional arrays
11+
12+
The following example shows how to use multi-dimensional arrays with structs.
13+
14+
```rust
15+
import std.array;
16+
17+
struct File {
18+
u8 width, height;
19+
std::Array<std::Array<u8, parent.width>, height> cells;
20+
};
21+
22+
File file @ 0x00;
23+
```
24+
925
*/
1026

1127
namespace auto std {
@@ -27,7 +43,7 @@ namespace auto std {
2743
struct ByteSizedArray<T, auto NumBytes> {
2844
u64 startAddress = $;
2945
T array[while($ - startAddress < NumBytes)] [[inline]];
30-
46+
3147
std::assert($ - startAddress == NumBytes, "Not enough bytes available to fit a whole number of types");
3248
} [[format("std::impl::format_array")]];
3349

0 commit comments

Comments
 (0)