Skip to main content

lichtung_plot_ndarray/
input.rs

1//! Sealed role protocols distinguish integer selectors, vectors, matrices and masks.
2use std::collections::HashSet;
3use std::ops::RangeFull;
4
5use ndarray::{ArrayView, ArrayView1, ArrayView2, Dimension, Ix1, Ix2};
6
7use crate::error::{binding, length, unsupported, BindingResult};
8use crate::{
9    ArrayElement, ArraySource, AxisValues, BooleanValues, CategoryValues, NumericValues, SourceRows,
10};
11
12pub(crate) mod sealed {
13    pub enum AxisKind {
14        Numeric,
15        Category,
16    }
17
18    pub trait Sealed {
19        fn native_slots(&self) -> bool {
20            false
21        }
22        fn cell_shape(&self) -> Option<(usize, usize)> {
23            None
24        }
25        fn selected_columns(&self) -> Option<&[usize]> {
26            None
27        }
28        fn column_identities(&self) -> Option<&[(usize, &str)]> {
29            None
30        }
31        fn axis_kind(&self, _: usize, role: &'static str) -> super::BindingResult<AxisKind> {
32            Err(super::binding(
33                role,
34                "this input is not an array axis source",
35            ))
36        }
37    }
38}
39fn axis_kind<T: ArrayElement>(index: usize, role: &'static str) -> BindingResult<sealed::AxisKind> {
40    if T::NUMERIC {
41        Ok(sealed::AxisKind::Numeric)
42    } else if T::CATEGORY {
43        Ok(sealed::AxisKind::Category)
44    } else {
45        Err(crate::error::unsupported_column::<T>(role, index))
46    }
47}
48impl sealed::Sealed for usize {}
49impl sealed::Sealed for RangeFull {}
50impl<T> sealed::Sealed for ArrayView1<'_, T> {}
51impl<T: ArrayElement> sealed::Sealed for ArrayView2<'_, T> {
52    fn cell_shape(&self) -> Option<(usize, usize)> {
53        Some(self.dim())
54    }
55    fn axis_kind(&self, index: usize, role: &'static str) -> BindingResult<sealed::AxisKind> {
56        axis_kind::<T>(index, role)
57    }
58}
59impl<T> sealed::Sealed for (ArrayView1<'_, T>, ArrayView1<'_, bool>) {}
60impl<T: ArrayElement> sealed::Sealed for (ArrayView2<'_, T>, ArrayView2<'_, bool>) {
61    fn cell_shape(&self) -> Option<(usize, usize)> {
62        Some(self.0.dim())
63    }
64    fn axis_kind(&self, index: usize, role: &'static str) -> BindingResult<sealed::AxisKind> {
65        axis_kind::<T>(index, role)
66    }
67}
68macro_rules! native {
69    ($($ty:ty),+) => {$ (impl sealed::Sealed for $ty { fn native_slots(&self) -> bool { true } })+};
70}
71native!(
72    NumericValues,
73    CategoryValues,
74    BooleanValues,
75    SourceRows,
76    AxisValues
77);
78
79type Raw<T> = (String, Vec<Option<T>>);
80
81pub(crate) fn repeat<T: Clone>(
82    values: Vec<Option<T>>,
83    copies: usize,
84    role: &'static str,
85) -> BindingResult<Vec<Option<T>>> {
86    let len = values
87        .len()
88        .checked_mul(copies)
89        .ok_or_else(|| binding(role, "expanded slot count exceeds usize"))?;
90    let mut expanded = crate::snapshot::allocate(len, role)?;
91    expanded.extend(
92        values
93            .into_iter()
94            .flat_map(|value| std::iter::repeat_n(value, copies)),
95    );
96    Ok(expanded)
97}
98
99macro_rules! role_input {
100    ($trait:ident, $bind:ident, $raw:ident, $repeated:ident, $ty:ty, $native:ident, $bound:path, $supported:ident, $convert:expr, $column:ident, $construct:expr) => {
101        #[doc = concat!("Sealed ", stringify!($trait), " role: logical column index, foreign vector, validity pair or native values.")]
102        pub trait $trait: sealed::Sealed + Sized {
103            #[doc(hidden)] fn $raw(self, source: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<Raw<$ty>>;
104            #[doc(hidden)] fn $bind(self, source: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<$native> {
105                let (name, values) = self.$raw(source, role)?;
106                ($construct)(name, values)
107            }
108            #[doc(hidden)] fn $repeated(self, source: Option<&dyn ArraySource>, role: &'static str, copies: usize) -> BindingResult<$native> {
109                let (name, values) = self.$raw(source, role)?;
110                ($construct)(name, repeat(values, copies, role)?)
111            }
112        }
113        impl $trait for usize {
114            fn $raw(self, source: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<Raw<$ty>> {
115                let source = crate::source::lookup(source, self, role)?;
116                let values = source.$column(self, role)?;
117                Ok((crate::source::identity(Some(source), self, role)?, values))
118            }
119        }
120        impl<T: ArrayElement + $bound> $trait for ArrayView1<'_, T> {
121            fn $raw(self, _: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<Raw<$ty>> {
122                if !T::$supported { return Err(unsupported::<T>(role)); }
123                Ok((role.into(), crate::snapshot::values(self, None, $convert, role)?))
124            }
125        }
126        impl<T: ArrayElement + $bound> $trait for (ArrayView1<'_, T>, ArrayView1<'_, bool>) {
127            fn $raw(self, _: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<Raw<$ty>> {
128                if !T::$supported { return Err(unsupported::<T>(role)); }
129                Ok((role.into(), crate::snapshot::values(self.0, Some(self.1), $convert, role)?))
130            }
131        }
132        impl $trait for $native {
133            fn $raw(self, _: Option<&dyn ArraySource>, role: &'static str) -> BindingResult<Raw<$ty>> { Err(binding(role, "use a foreign variable in this mapping role")) }
134            fn $bind(self, _: Option<&dyn ArraySource>, _: &'static str) -> BindingResult<$native> { Ok(self) }
135            fn $repeated(self, _: Option<&dyn ArraySource>, _: &'static str, _: usize) -> BindingResult<$native> { Ok(self) }
136        }
137    };
138}
139role_input!(
140    NumericInput,
141    bind_numeric,
142    raw_numeric,
143    bind_numeric_repeated,
144    f64,
145    NumericValues,
146    crate::NumericElement,
147    NUMERIC,
148    ArrayElement::numeric,
149    numeric_column,
150    |name, values| Ok(NumericValues::nullable(name, values))
151);
152role_input!(
153    CategoryInput,
154    bind_category,
155    raw_category,
156    bind_category_repeated,
157    String,
158    CategoryValues,
159    crate::CategoryElement,
160    CATEGORY,
161    |value| value.category().map(str::to_owned),
162    category_column,
163    |name, values| Ok(CategoryValues::nullable(name, values)?)
164);
165role_input!(
166    BooleanInput,
167    bind_boolean,
168    raw_boolean,
169    bind_boolean_repeated,
170    bool,
171    BooleanValues,
172    crate::BooleanElement,
173    BOOLEAN,
174    ArrayElement::boolean,
175    boolean_column,
176    |name, values| Ok(BooleanValues::nullable(name, values))
177);
178
179/// Exact source IDs: integer vectors, same-shape cell grids or native IDs.
180pub trait SourceRowsInput: sealed::Sealed + Sized {
181    #[doc(hidden)]
182    fn raw_source_rows(
183        self,
184        _: Option<&dyn ArraySource>,
185        role: &'static str,
186    ) -> BindingResult<Vec<usize>> {
187        Err(binding(
188            role,
189            "use an integer foreign variable for a generated-column selector",
190        ))
191    }
192    #[doc(hidden)]
193    fn bind_source_rows(
194        self,
195        source: Option<&dyn ArraySource>,
196        role: &'static str,
197    ) -> BindingResult<SourceRows>;
198    #[doc(hidden)]
199    fn bind_source_rows_repeated(
200        self,
201        source: Option<&dyn ArraySource>,
202        role: &'static str,
203        copies: usize,
204    ) -> BindingResult<SourceRows> {
205        if copies != 1
206            && !self.native_slots()
207            && self.cell_shape().is_none()
208            && self.selected_columns().is_none()
209        {
210            return Err(binding(
211                role,
212                "provide unique per-cell IDs, not repeated row IDs",
213            ));
214        }
215        self.bind_source_rows(source, role)
216    }
217}
218impl SourceRowsInput for SourceRows {
219    fn bind_source_rows(
220        self,
221        _: Option<&dyn ArraySource>,
222        _: &'static str,
223    ) -> BindingResult<SourceRows> {
224        Ok(self)
225    }
226}
227impl SourceRowsInput for usize {
228    fn raw_source_rows(
229        self,
230        source: Option<&dyn ArraySource>,
231        role: &'static str,
232    ) -> BindingResult<Vec<usize>> {
233        crate::source::lookup(source, self, role)?.id_column(self, role)
234    }
235    fn bind_source_rows(
236        self,
237        source: Option<&dyn ArraySource>,
238        role: &'static str,
239    ) -> BindingResult<SourceRows> {
240        Ok(SourceRows::new(
241            crate::source::lookup(source, self, role)?.id_column(self, role)?,
242        )?)
243    }
244}
245
246pub(crate) fn ids<T: ArrayElement, D: Dimension>(
247    values: ArrayView<'_, T, D>,
248    present: Option<ArrayView<'_, bool, D>>,
249    role: &'static str,
250) -> BindingResult<Vec<usize>> {
251    if !T::ID {
252        return Err(unsupported::<T>(role));
253    }
254    let converted = crate::snapshot::values(values.view(), present, ArrayElement::id, role)?;
255    let mut result = crate::snapshot::allocate(values.len(), role)?;
256    for (slot, (value, id)) in values.iter().zip(converted).enumerate() {
257        result.push(id.ok_or_else(|| crate::AdapterError::SourceRow {
258            slot,
259            value: format!("{value:?}"),
260            column: None,
261        })?);
262    }
263    Ok(result)
264}
265pub(crate) fn bytes<T: ArrayElement, D: Dimension>(
266    values: ArrayView<'_, T, D>,
267    present: Option<ArrayView<'_, bool, D>>,
268    role: &'static str,
269) -> BindingResult<Vec<u8>> {
270    if !T::BYTE {
271        return Err(unsupported::<T>(role));
272    }
273    crate::snapshot::values(values, present, ArrayElement::byte, role)?
274        .into_iter()
275        .enumerate()
276        .map(|(slot, value)| {
277            value.ok_or_else(|| binding(role, format!("missing byte at logical slot {slot}")))
278        })
279        .collect()
280}
281macro_rules! source_ids {
282    ($dim:ty) => {
283        impl<T: ArrayElement> SourceRowsInput for ArrayView<'_, T, $dim> {
284            fn raw_source_rows(
285                self,
286                _: Option<&dyn ArraySource>,
287                role: &'static str,
288            ) -> BindingResult<Vec<usize>> {
289                ids(self, None, role)
290            }
291            fn bind_source_rows(
292                self,
293                _: Option<&dyn ArraySource>,
294                role: &'static str,
295            ) -> BindingResult<SourceRows> {
296                Ok(SourceRows::new(ids(self, None, role)?)?)
297            }
298        }
299        impl<T: ArrayElement> SourceRowsInput
300            for (ArrayView<'_, T, $dim>, ArrayView<'_, bool, $dim>)
301        {
302            fn raw_source_rows(
303                self,
304                _: Option<&dyn ArraySource>,
305                role: &'static str,
306            ) -> BindingResult<Vec<usize>> {
307                ids(self.0, Some(self.1), role)
308            }
309            fn bind_source_rows(
310                self,
311                _: Option<&dyn ArraySource>,
312                role: &'static str,
313            ) -> BindingResult<SourceRows> {
314                Ok(SourceRows::new(ids(self.0, Some(self.1), role)?)?)
315            }
316        }
317    };
318}
319source_ids!(Ix1);
320source_ids!(Ix2);
321impl<T: ArrayElement> BooleanInput for ArrayView2<'_, T> {
322    fn raw_boolean(
323        self,
324        _: Option<&dyn ArraySource>,
325        role: &'static str,
326    ) -> BindingResult<Raw<bool>> {
327        if !T::BOOLEAN {
328            return Err(unsupported::<T>(role));
329        }
330        Ok((
331            role.into(),
332            crate::snapshot::values(self, None, ArrayElement::boolean, role)?,
333        ))
334    }
335}
336impl<T: ArrayElement> BooleanInput for (ArrayView2<'_, T>, ArrayView2<'_, bool>) {
337    fn raw_boolean(
338        self,
339        _: Option<&dyn ArraySource>,
340        role: &'static str,
341    ) -> BindingResult<Raw<bool>> {
342        if !T::BOOLEAN {
343            return Err(unsupported::<T>(role));
344        }
345        Ok((
346            role.into(),
347            crate::snapshot::values(self.0, Some(self.1), ArrayElement::boolean, role)?,
348        ))
349    }
350}
351
352/// Numeric or categorical trajectory x; Boolean input is never a numeric coordinate.
353pub trait AxisInput: sealed::Sealed {
354    #[doc(hidden)]
355    fn bind_axis(
356        self,
357        source: Option<&dyn ArraySource>,
358        role: &'static str,
359    ) -> BindingResult<AxisValues>;
360}
361impl AxisInput for usize {
362    fn bind_axis(
363        self,
364        source: Option<&dyn ArraySource>,
365        role: &'static str,
366    ) -> BindingResult<AxisValues> {
367        crate::source::lookup(source, self, role)?.axis_column(self, role)
368    }
369}
370fn axis<T: ArrayElement>(
371    values: ArrayView1<'_, T>,
372    present: Option<ArrayView1<'_, bool>>,
373    role: &'static str,
374) -> BindingResult<AxisValues> {
375    if T::NUMERIC {
376        Ok(AxisValues::Numeric(NumericValues::nullable(
377            role,
378            crate::snapshot::values(values, present, ArrayElement::numeric, role)?,
379        )))
380    } else if T::CATEGORY {
381        Ok(AxisValues::Category(CategoryValues::nullable(
382            role,
383            crate::snapshot::values(
384                values,
385                present,
386                |value| value.category().map(str::to_owned),
387                role,
388            )?,
389        )?))
390    } else {
391        Err(unsupported::<T>(role))
392    }
393}
394impl<T: ArrayElement> AxisInput for ArrayView1<'_, T> {
395    fn bind_axis(
396        self,
397        _: Option<&dyn ArraySource>,
398        role: &'static str,
399    ) -> BindingResult<AxisValues> {
400        axis(self, None, role)
401    }
402}
403impl<T: ArrayElement> AxisInput for (ArrayView1<'_, T>, ArrayView1<'_, bool>) {
404    fn bind_axis(
405        self,
406        _: Option<&dyn ArraySource>,
407        role: &'static str,
408    ) -> BindingResult<AxisValues> {
409        axis(self.0, Some(self.1), role)
410    }
411}
412impl AxisInput for AxisValues {
413    fn bind_axis(self, _: Option<&dyn ArraySource>, _: &'static str) -> BindingResult<AxisValues> {
414        Ok(self)
415    }
416}
417impl AxisInput for NumericValues {
418    fn bind_axis(self, _: Option<&dyn ArraySource>, _: &'static str) -> BindingResult<AxisValues> {
419        Ok(AxisValues::Numeric(self))
420    }
421}
422impl AxisInput for CategoryValues {
423    fn bind_axis(self, _: Option<&dyn ArraySource>, _: &'static str) -> BindingResult<AxisValues> {
424        Ok(AxisValues::Category(self))
425    }
426}
427
428pub(crate) type Columns = (usize, Vec<(usize, Vec<Option<f64>>)>);
429pub(crate) type SeriesBinding = (NumericValues, Option<(usize, Vec<usize>, bool)>);
430
431/// Ordered logical source columns, `..`, or a direct matrix/validity pair.
432pub trait ColumnsInput: sealed::Sealed {
433    #[doc(hidden)]
434    fn local_identities(&self) -> bool {
435        false
436    }
437    #[doc(hidden)]
438    fn bind_columns(self, source: Option<&dyn ArraySource>) -> BindingResult<Columns>;
439}
440pub(crate) fn selected(
441    source: Option<&dyn ArraySource>,
442    indices: &[usize],
443) -> BindingResult<Columns> {
444    if indices.is_empty() {
445        return Err(binding("selected columns", "select at least one variable"));
446    }
447    let mut seen = HashSet::new();
448    let mut columns = crate::snapshot::allocate(indices.len(), "selected columns")?;
449    seen.try_reserve(indices.len())
450        .map_err(|source| crate::AdapterError::Allocation {
451            operation: "selection identities",
452            source,
453        })?;
454    let mut rows = 0;
455    for &index in indices {
456        if !seen.insert(index) {
457            return Err(binding(
458                "selected columns",
459                format!("duplicate column {index}"),
460            ));
461        }
462        let source = crate::source::lookup(source, index, "selected columns")?;
463        rows = source.shape().0;
464        columns.push((index, source.numeric_column(index, "selected columns")?));
465    }
466    Ok((rows, columns))
467}
468impl sealed::Sealed for &[usize] {
469    fn selected_columns(&self) -> Option<&[usize]> {
470        Some(self)
471    }
472}
473impl<const N: usize> sealed::Sealed for [usize; N] {
474    fn selected_columns(&self) -> Option<&[usize]> {
475        Some(self)
476    }
477}
478impl ColumnsInput for &[usize] {
479    fn bind_columns(self, source: Option<&dyn ArraySource>) -> BindingResult<Columns> {
480        selected(source, self)
481    }
482}
483impl<const N: usize> ColumnsInput for [usize; N] {
484    fn bind_columns(self, source: Option<&dyn ArraySource>) -> BindingResult<Columns> {
485        selected(source, &self)
486    }
487}
488impl ColumnsInput for RangeFull {
489    fn bind_columns(self, source: Option<&dyn ArraySource>) -> BindingResult<Columns> {
490        let source = source
491            .ok_or_else(|| binding("selected columns", "all columns require an array source"))?;
492        let mut indices = crate::snapshot::allocate(source.shape().1, "selected columns")?;
493        indices.extend(0..source.shape().1);
494        selected(Some(source), &indices)
495    }
496}
497impl<T: ArrayElement> ColumnsInput for ArrayView2<'_, T> {
498    fn local_identities(&self) -> bool {
499        true
500    }
501    fn bind_columns(self, _: Option<&dyn ArraySource>) -> BindingResult<Columns> {
502        (..).bind_columns(Some(&self))
503    }
504}
505impl<T: ArrayElement> ColumnsInput for (ArrayView2<'_, T>, ArrayView2<'_, bool>) {
506    fn local_identities(&self) -> bool {
507        true
508    }
509    fn bind_columns(self, _: Option<&dyn ArraySource>) -> BindingResult<Columns> {
510        (..).bind_columns(Some(&self))
511    }
512}
513
514pub(crate) fn multiple(
515    (rows, columns): Columns,
516    local: bool,
517    role: &'static str,
518) -> BindingResult<SeriesBinding> {
519    let cells = rows
520        .checked_mul(columns.len())
521        .ok_or_else(|| binding(role, "expanded slot count exceeds usize"))?;
522    let mut values = crate::snapshot::allocate(cells, role)?;
523    for row in 0..rows {
524        for (_, column) in &columns {
525            length(role, role, rows, column.len())?;
526            values.push(column[row]);
527        }
528    }
529    Ok((
530        NumericValues::nullable(role, values),
531        Some((
532            rows,
533            columns.into_iter().map(|(index, _)| index).collect(),
534            local,
535        )),
536    ))
537}
538/// One numeric variable or explicit logical-column/matrix expansion.
539pub trait NumericSeriesInput: sealed::Sealed {
540    #[doc(hidden)]
541    fn bind_series(
542        self,
543        source: Option<&dyn ArraySource>,
544        role: &'static str,
545    ) -> BindingResult<SeriesBinding>;
546}
547impl NumericSeriesInput for usize {
548    fn bind_series(
549        self,
550        source: Option<&dyn ArraySource>,
551        role: &'static str,
552    ) -> BindingResult<SeriesBinding> {
553        Ok((self.bind_numeric(source, role)?, None))
554    }
555}
556impl NumericSeriesInput for NumericValues {
557    fn bind_series(
558        self,
559        _: Option<&dyn ArraySource>,
560        _: &'static str,
561    ) -> BindingResult<SeriesBinding> {
562        Ok((self, None))
563    }
564}
565macro_rules! one_series {
566    ($ty:ty) => {
567        impl<T: ArrayElement + crate::NumericElement> NumericSeriesInput for $ty {
568            fn bind_series(
569                self,
570                source: Option<&dyn ArraySource>,
571                role: &'static str,
572            ) -> BindingResult<SeriesBinding> {
573                Ok((self.bind_numeric(source, role)?, None))
574            }
575        }
576    };
577}
578one_series!(ArrayView1<'_, T>);
579one_series!((ArrayView1<'_, T>, ArrayView1<'_, bool>));
580macro_rules! matrix_series {
581    ($ty:ty) => {
582        impl<T: ArrayElement> NumericSeriesInput for $ty {
583            fn bind_series(
584                self,
585                source: Option<&dyn ArraySource>,
586                role: &'static str,
587            ) -> BindingResult<SeriesBinding> {
588                multiple(self.bind_columns(source)?, true, role)
589            }
590        }
591    };
592}
593matrix_series!(ArrayView2<'_, T>);
594matrix_series!((ArrayView2<'_, T>, ArrayView2<'_, bool>));
595impl NumericSeriesInput for &[usize] {
596    fn bind_series(
597        self,
598        source: Option<&dyn ArraySource>,
599        role: &'static str,
600    ) -> BindingResult<SeriesBinding> {
601        multiple(self.bind_columns(source)?, false, role)
602    }
603}
604impl<const N: usize> NumericSeriesInput for [usize; N] {
605    fn bind_series(
606        self,
607        source: Option<&dyn ArraySource>,
608        role: &'static str,
609    ) -> BindingResult<SeriesBinding> {
610        multiple(self.bind_columns(source)?, false, role)
611    }
612}
613
614fn cell_columns<T: Clone>(
615    source: Option<&dyn ArraySource>,
616    indices: &[usize],
617    role: &'static str,
618    read: impl Fn(&dyn ArraySource, usize) -> BindingResult<Vec<T>>,
619) -> BindingResult<Vec<T>> {
620    let first = *indices
621        .first()
622        .ok_or_else(|| binding(role, "select at least one column"))?;
623    let source = crate::source::lookup(source, first, role)?;
624    let rows = source.shape().0;
625    let cells = rows
626        .checked_mul(indices.len())
627        .ok_or_else(|| binding(role, "cell count exceeds usize"))?;
628    let mut columns = crate::snapshot::allocate(indices.len(), role)?;
629    let mut seen = HashSet::new();
630    seen.try_reserve(indices.len())
631        .map_err(|source| crate::AdapterError::Allocation {
632            operation: role,
633            source,
634        })?;
635    for &index in indices {
636        if !seen.insert(index) {
637            return Err(binding(role, format!("duplicate column {index}")));
638        }
639        crate::source::lookup(Some(source), index, role)?;
640        columns.push(read(source, index)?);
641    }
642    let mut values = crate::snapshot::allocate(cells, role)?;
643    for row in 0..rows {
644        for column in &columns {
645            values.push(column[row].clone());
646        }
647    }
648    Ok(values)
649}
650impl BooleanInput for &[usize] {
651    fn raw_boolean(
652        self,
653        source: Option<&dyn ArraySource>,
654        role: &'static str,
655    ) -> BindingResult<Raw<bool>> {
656        Ok((
657            role.into(),
658            cell_columns(source, self, role, |source, index| {
659                source.boolean_column(index, role)
660            })?,
661        ))
662    }
663    fn bind_boolean_repeated(
664        self,
665        source: Option<&dyn ArraySource>,
666        role: &'static str,
667        _: usize,
668    ) -> BindingResult<BooleanValues> {
669        self.bind_boolean(source, role)
670    }
671}
672impl<const N: usize> BooleanInput for [usize; N] {
673    fn raw_boolean(
674        self,
675        source: Option<&dyn ArraySource>,
676        role: &'static str,
677    ) -> BindingResult<Raw<bool>> {
678        self.as_slice().raw_boolean(source, role)
679    }
680    fn bind_boolean_repeated(
681        self,
682        source: Option<&dyn ArraySource>,
683        role: &'static str,
684        _: usize,
685    ) -> BindingResult<BooleanValues> {
686        self.bind_boolean(source, role)
687    }
688}
689impl SourceRowsInput for &[usize] {
690    fn raw_source_rows(
691        self,
692        source: Option<&dyn ArraySource>,
693        role: &'static str,
694    ) -> BindingResult<Vec<usize>> {
695        cell_columns(source, self, role, |source, index| {
696            source.id_column(index, role)
697        })
698    }
699    fn bind_source_rows(
700        self,
701        source: Option<&dyn ArraySource>,
702        role: &'static str,
703    ) -> BindingResult<SourceRows> {
704        Ok(SourceRows::new(self.raw_source_rows(source, role)?)?)
705    }
706}
707impl<const N: usize> SourceRowsInput for [usize; N] {
708    fn raw_source_rows(
709        self,
710        source: Option<&dyn ArraySource>,
711        role: &'static str,
712    ) -> BindingResult<Vec<usize>> {
713        self.as_slice().raw_source_rows(source, role)
714    }
715    fn bind_source_rows(
716        self,
717        source: Option<&dyn ArraySource>,
718        role: &'static str,
719    ) -> BindingResult<SourceRows> {
720        self.as_slice().bind_source_rows(source, role)
721    }
722}