From d2d42bf3ef5490f6fdec73508c2493a666ecee41 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 30 Apr 2025 16:48:07 -0400 Subject: Setup variants for all allocating modules This harmonizes the allocating modules in a couple of ways. All can now be constructed by pointer, and all treat various miscellaneous read failures as `unreachable`, which indeed they should be. The README has been updated to inform users of this option. --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 80e544f..538a38d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,24 @@ zg is a modular library. This approach minimizes binary file size and memory requirements by only including the Unicode data required for the specified module. The following sections describe the various modules and their specific use case. +### Init and Setup + +The code examples will show the use of `Module.init(allocator)` to create the +various modules. All of the allocating modules have a `setup` variant, which +takes a pointer and allocates in-place. + +Example use: + +```zig +test "Setup form" { + var graphemes = try allocator.create(Graphemes); + defer allocator.destroy(graphemes); + try graphemes.setup(allocator); + defer graphemes.deinit(allocator); +} +``` + + ## Code Points In the `code_point` module, you'll find a data structure representing a single code @@ -386,6 +404,8 @@ test "Initialize With a Normalize" { defer case_fold.deinit(allocator); } ``` +This has a `setupWithNormalize` variant as well, but note that this also takes +a `Normalize` struct, and not a pointer to it. ## Display Width of Characters and Strings -- cgit v1.2.3