objectiveai_sdk/functions/check/example_inputs/
boolean.rs1use rand::Rng;
2use rand::seq::SliceRandom;
3
4use crate::functions::expression::{BooleanInputSchema, InputValue};
5
6pub const fn permutations(_schema: &BooleanInputSchema) -> usize {
7 2usize
8}
9
10pub fn generate<R: Rng>(
11 _schema: &BooleanInputSchema,
12 mut rng: R,
13) -> Generator<R> {
14 let mut indices: Vec<usize> = (0..2).collect();
15 indices.shuffle(&mut rng);
16 Generator {
17 indices,
18 pos: 0,
19 rng,
20 }
21}
22
23pub struct Generator<R: Rng> {
24 indices: Vec<usize>,
25 pos: usize,
26 rng: R,
27}
28
29impl<R: Rng> Iterator for Generator<R> {
30 type Item = InputValue;
31 fn next(&mut self) -> Option<InputValue> {
32 if self.pos >= self.indices.len() {
33 self.indices.shuffle(&mut self.rng);
34 self.pos = 0;
35 }
36 let index = self.indices[self.pos];
37 self.pos += 1;
38 Some(InputValue::Boolean(index == 0))
39 }
40}