From 0ca0f77e04465902d0f31caf73436c9a02d33f2b Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Sat, 3 May 2025 21:45:58 +0300 Subject: [PATCH] Adjust comment. --- src/util/SmartString.zig | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/util/SmartString.zig b/src/util/SmartString.zig index 347347c..7ac28d1 100644 --- a/src/util/SmartString.zig +++ b/src/util/SmartString.zig @@ -1,23 +1,24 @@ +//! SmartString is a memory-aware string type that provides explicit tracking of allocation state. +//! It maintains information about whether the underlying string data is: +//! - Allocated: Owned by an allocator and must be freed +//! - Constant: Compile-time constant that requires no freeing +//! - Dead: Already freed (helps catch use-after-free in debug builds) +//! +//! This type is particularly useful in scenarios where string ownership needs to be +//! explicit, such as logging systems or string caches where mixing allocated and +//! constant strings is common. +//! +//! Example: +//! ``` +//! const str1 = try SmartString.alloc("hello", allocator); +//! defer str1.deinit(); +//! +//! const str2 = SmartString.constant("world"); +//! defer str2.deinit(); // Safe to call deinit() even on constants +//! ``` + const std = @import("std"); -/// SmartString is a memory-aware string type that provides explicit tracking of allocation state. -/// It maintains information about whether the underlying string data is: -/// - Allocated: Owned by an allocator and must be freed -/// - Constant: Compile-time constant that requires no freeing -/// - Dead: Already freed (helps catch use-after-free in debug builds) -/// -/// This type is particularly useful in scenarios where string ownership needs to be -/// explicit, such as logging systems or string caches where mixing allocated and -/// constant strings is common. -/// -/// Example: -/// ``` -/// const str1 = try SmartString.alloc("hello", allocator); -/// defer str1.deinit(); -/// -/// const str2 = SmartString.constant("world"); -/// defer str2.deinit(); // Safe to call deinit() even on constants -/// ``` /// The actual string data. This becomes undefined after calling `deinit()`. data: []const u8, /// Tracks the allocation state of the string.