Function fromSliceAlloc [src]

Like fromSlice, but the result may contain pointers. To automatically free the result, see free.

Prototype

pub fn fromSliceAlloc( T: type, gpa: Allocator, source: [:0]const u8, diag: ?*Diagnostics, options: Options, ) error{ OutOfMemory, ParseZon }!T

Parameters

T: typeThe 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. gpa: Allocatorsource: [:0]const u8diag: ?*Diagnosticsoptions: Options

Possible Errors

OutOfMemory
ParseZon

Source

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{ OutOfMemory, ParseZon }!T { if (diag) |s| s.assertEmpty(); var ast = try std.zig.Ast.parse(gpa, source, .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); }