mirror of
https://github.com/ziglang/zig.git
synced 2025-02-16 09:30:17 +00:00
Some tweeks, examples, and sweet ASCII tree because ASCII trees make everything better.
parent
519a8215c0
commit
287483b2a1
@ -4,11 +4,30 @@
|
||||
You can find it under [`/lib/std/`](https://github.com/ziglang/zig/tree/master/lib/std).
|
||||
|
||||
## How is the stdlib structured?
|
||||
When you import "std" in a Zig source file, you are importing `/lib/std/std.zig`.
|
||||
In that file you can see where each exposed symbol comes from.
|
||||
|
||||
Some parts of the stdlib are simple and are implemented in a single file, like `std.ascii`, which is entirely implemented in `/lib/std/ascii.zig`. Some other parts of the standard library are beefier and so have their own dedicated subdirectory, like `std.math`.
|
||||
Those beefier "submodules" always have a regular structure:
|
||||
When you import "std" in a Zig source file, you are importing [`/lib/std/std.zig`](https://github.com/ziglang/zig/tree/master/lib/std/std.zig).
|
||||
|
||||
```zig
|
||||
const std = @import("std");
|
||||
```
|
||||
|
||||
In that file you can see where each exposed symbol comes from:
|
||||
|
||||
```zig
|
||||
// Excerpt from std.zig
|
||||
...
|
||||
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
|
||||
pub const ArrayHashMapUnmanaged = array_hash_map.ArrayHashMapUnmanaged;
|
||||
pub const ArrayList = @import("array_list.zig").ArrayList;
|
||||
pub const ArrayListAligned = @import("array_list.zig").ArrayListAligned;
|
||||
pub const ArrayListAlignedUnmanaged = @import("array_list.zig").ArrayListAlignedUnmanaged;
|
||||
pub const ArrayListUnmanaged = @import("array_list.zig").ArrayListUnmanaged;
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
Some parts of the stdlib are simple and are implemented in a single file, like `std.ascii`, which is entirely implemented in `/lib/std/ascii.zig`.
|
||||
|
||||
Other parts of the standard library are beefier and have their own dedicated subdirectory, like `std.math`. These "submodules" always have a regular structure:
|
||||
- A subdirectory that contains most of the implementation
|
||||
- A file inside `/lib/std/` that exposes the public parts implemented in the relative subdirectory
|
||||
|
||||
@ -18,6 +37,18 @@ In the case of `std.math`, for example, `/lib/std/math/ceil.zig` contains the im
|
||||
pub const ceil = @import("math/ceil.zig").ceil;
|
||||
```
|
||||
|
||||
The directory tree of the `std.ascii` and `std.math` files described above are arranged like so:
|
||||
|
||||
```
|
||||
.
|
||||
`-- lib/
|
||||
`-- std/
|
||||
|-- ascii.zig
|
||||
|-- math/
|
||||
| `-- ceil.zig
|
||||
`-- math.zig
|
||||
```
|
||||
|
||||
With this knowledge it should be easy for you to track down the implementation code of every symbol defined in the standard library.
|
||||
|
||||
One final trick: search for `pub fn` and `pub const` to quickly skim over the public API of an implementation.
|
||||
|
Loading…
Reference in New Issue
Block a user