const std = @import("std"); pub fn main() !void { // Example showing the conversion steps // Step 1: SQLite gives us this type (simplified) const sqlite_ptr: ?*const u8 = "hello"; // Step 2: Check if it's not null if (sqlite_ptr != null) { // Step 3: Cast to sentinel-terminated pointer // @as(TargetType, value) - explicit type conversion // [*:0]const u8 - pointer to many u8s, terminated by 0 const sentinel_ptr = @as([*:0]const u8, @ptrCast(sqlite_ptr)); // Step 4: Convert sentinel pointer to slice // std.mem.span finds the 0 terminator and creates a slice const slice: []const u8 = std.mem.span(sentinel_ptr); std.debug.print("Slice: {s}, Length: {}\n", .{slice, slice.len}); } // The one-liner version from our code: const text = if (sqlite_ptr != null) std.mem.span(@as([*:0]const u8, @ptrCast(sqlite_ptr))) else ""; }