mz_repr/
fixed_length.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Provides abstractions for types that can be converted into `Datum` iterators.
11//! `Row` is the most obvious implementor, but other trace types that may use more advanced
12//! representations only need to commit to implementing these traits.
13
14use crate::row::DatumListIter;
15use crate::{Datum, Row};
16
17/// A helper trait to turn a type into an iterator of datums.
18pub trait ToDatumIter: Sized {
19    /// An iterator type for use in `to_datum_iter`.
20    type DatumIter<'a>: IntoIterator<Item = Datum<'a>>
21    where
22        Self: 'a;
23
24    /// Obtains an iterator of datums out of an instance of `&Self`.
25    fn to_datum_iter(&self) -> Self::DatumIter<'_>;
26}
27
28impl<'b, T: ToDatumIter> ToDatumIter for &'b T {
29    type DatumIter<'a>
30        = T::DatumIter<'a>
31    where
32        Self: 'a;
33    fn to_datum_iter(&self) -> Self::DatumIter<'_> {
34        (**self).to_datum_iter()
35    }
36}
37
38// Blanket identity implementation for Row.
39impl ToDatumIter for Row {
40    /// Datum iterator for `Row`.
41    type DatumIter<'a> = DatumListIter<'a>;
42
43    /// Borrows `self` and gets an iterator from it.
44    #[inline]
45    fn to_datum_iter(&self) -> Self::DatumIter<'_> {
46        self.iter()
47    }
48}