Skip to documentation
SLOP

tiny.zen.QuizPlan

Reference tiny.zen QuizPlan

Defined in tiny.zen.

API (6)

Actions

Public operations.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.zenQuizPlan
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/zen/src/quiz/plan.zig:17

zig
pub const Plan = struct {    input_bytes: usize,    questions: usize,    options: usize,    joined_text_bytes: usize,    pub fn inspect(source: []const u8, limits: Limits) model.Error!Plan {        var state: State = .{};        var iterator = scan.Iterator.init(source);        while (iterator.next()) |token| switch (token) {            .prompt => |text| {                if (state.current.started()) try state.current.finish();                state.questions = try added(state.questions, 1);                if (state.questions > limits.max_questions) {                    return error.QuestionCapacityExceeded;                }                state.current = .{                    .element = .prompt,                    .element_bytes = text.len,                };            },            .option => |option| {                if (!state.current.started() or state.current.element == .explanation) {                    return error.InvalidQuizDirective;                }                state.options = try added(state.options, 1);                if (state.options > limits.max_options) return error.OptionCapacityExceeded;                state.current.options = try added(state.current.options, 1);                if (option.correct) {                    state.current.correct = try added(state.current.correct, 1);                }                state.current.element = .option;                state.current.element_bytes = option.text.len;                state.current.element_joined = false;            },            .explanation => |text| {                if (!state.current.started()) return error.InvalidQuizDirective;                if (state.current.element == .explanation) {                    try state.join(text, limits.max_joined_text_bytes);                } else {                    state.current.element = .explanation;                    state.current.element_bytes = text.len;                    state.current.element_joined = false;                    state.current.explanation_bytes = text.len;                }            },            .continuation => |text| {                if (!state.current.started()) return error.InvalidQuizDirective;                try state.join(text, limits.max_joined_text_bytes);            },        };        if (state.current.started()) try state.current.finish();        if (state.questions == 0) return error.InvalidQuizDirective;        std.debug.assert(state.questions <= limits.max_questions);        std.debug.assert(state.options <= limits.max_options);        std.debug.assert(state.joined_text_bytes <= limits.max_joined_text_bytes);        return .{            .input_bytes = source.len,            .questions = state.questions,            .options = state.options,            .joined_text_bytes = state.joined_text_bytes,        };    }    pub fn exactLimits(self: Plan) Limits {        return .{            .max_questions = self.questions,            .max_options = self.options,            .max_joined_text_bytes = self.joined_text_bytes,        };    }};

Source: lib/zen/src/root.zig:150

zig
/// Exact quiz storage demand measured before allocation.pub const QuizPlan = quiz.Plan;
Called byCallstest sourcelib.zen.src.quiz.plantest: quiz plan borrows every unconti...test sourcelib.zen.src.quiz.plantest: quiz plan counts descriptors an...private sourcelib.zen.src.quiz.plan.Statejoinprivate sourcelib.zen.src.quiz.planaddedQuizPlaninspect
Static calls · unresolved targets: 0 · external targets: 4.

Also reachable as

quiz.Plan.

Audit

Definitions3
Public names6
Members4
Version26.7.0
Revisiondaab053ee433