Function fromSlice [src]

Parses the given slice as ZON. Returns error.OutOfMemory on allocation failure, or error.ParseZon error if the ZON is invalid or can not be deserialized into type T. When the parser returns error.ParseZon, it will also store a human readable explanation in status if non null. If status is not null, it must be initialized to .{}.

Prototype

pub fn fromSlice( T: type, gpa: Allocator, source: [:0]const u8, status: ?*Status, 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 u8status: ?*Statusoptions: Options

Possible Errors

OutOfMemory
ParseZon

Source

pub fn fromSlice( /// 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, status: ?*Status, options: Options, ) error{ OutOfMemory, ParseZon }!T { if (status) |s| s.assertEmpty(); var ast = try std.zig.Ast.parse(gpa, source, .zon); defer if (status == null) ast.deinit(gpa); if (status) |s| s.ast = ast; // If there's no status, Zoir exists for the lifetime of this function. If there is a status, // ownership is transferred to status. var zoir = try ZonGen.generate(gpa, ast, .{ .parse_str_lits = false }); defer if (status == null) zoir.deinit(gpa); if (status) |s| s.* = .{}; return fromZoir(T, gpa, ast, zoir, status, options); }