pub fn fromSliceAlloc(
/// The type to deserialize into. May not be or contain any of the following types:
/// * Any comptime-only type, except in a comptime field
/// * `type`
/// * `void`, except as a union payload
/// * `noreturn`
/// * An error set/error union
/// * A many-pointer or C-pointer
/// * An opaque type, including `anyopaque`
/// * An async frame type, including `anyframe` and `anyframe->T`
/// * A function
///
/// All other types are valid. Unsupported types will fail at compile time.
T: type,
gpa: Allocator,
source: [:0]const u8,
diag: ?*Diagnostics,
options: Options,
) error T: typeThe type to deserialize into. May not be or contain any of the following types:
typevoid, except as a union payloadnoreturnanyopaqueanyframe and anyframe->TAll other types are valid. Unsupported types will fail at compile time.
gpa: Allocatorsource: [:0]const u8diag: ?*Diagnosticsoptions: Options275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307pub fn fromSliceAlloc(
/// The type to deserialize into. May not be or contain any of the following types:
/// * Any comptime-only type, except in a comptime field
/// * `type`
/// * `void`, except as a union payload
/// * `noreturn`
/// * An error set/error union
/// * A many-pointer or C-pointer
/// * An opaque type, including `anyopaque`
/// * An async frame type, including `anyframe` and `anyframe->T`
/// * A function
///
/// All other types are valid. Unsupported types will fail at compile time.
T: type,
gpa: Allocator,
source: [:0]const u8,
diag: ?*Diagnostics,
options: Options,
) error{ OutOfMemory, ParseZon }!T {
if (diag) |s| s.assertEmpty();
var ast = try std.zig.Ast.parse(gpa, source, .{ .mode = .zon });
defer if (diag == null) ast.deinit(gpa);
if (diag) |s| s.ast = ast;
// If there's no diagnostics, Zoir exists for the lifetime of this function. If there is a
// diagnostics, ownership is transferred to diagnostics.
var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false });
defer if (diag == null) zoir.deinit(gpa);
if (diag) |s| s.* = .{};
return fromZoirAlloc(T, gpa, ast, zoir, diag, options);
}
Like
fromSlice, but the result may contain pointers. To automatically free the result, seefree.