https://github.com/retrodev256/instinct
https://github.com/retrodev256/instinct
zig-package
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/retrodev256/instinct
- Owner: RetroDev256
- License: mit
- Created: 2024-11-07T17:49:29.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-07T18:03:44.000Z (over 1 year ago)
- Last Synced: 2025-02-28T16:12:45.565Z (about 1 year ago)
- Topics: zig-package
- Language: Zig
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Instinct
An ultra simple set of distinct integer types.
### Use cases:
- You don't want to mix up array index types
- You want safety checks on an integer that must have a range
- You want the above, but with a value that represents null
### Types:
```zig
pub fn OptionalRangedInt(
comptime T: type,
comptime type_id: u32,
comptime range: Range(T),
comptime null_value: T,
) type { ... }
pub fn OptionalInt(
comptime T: type,
comptime type_id: u32,
comptime null_value: T,
) type { ... }
pub fn RangedInt(
comptime T: type,
comptime type_id: u32,
comptime range: Range(T),
) type { ... }
pub fn Int(
comptime T: type,
comptime type_id: u32,
) type { ... }
```
### Methods:
Each type provides the following methods:
- `init` creates a new distinct type
- `set` changes the value of the distinct type
- `val` fetches the value of the distinct type
- `cast` converts the distinct type to another distinct type
Limitation: you can't directly cast from an optional to non-optional type