risingwave_common/row/
empty.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::{Row, assert_row};
16use crate::types::DatumRef;
17
18/// Row for the [`empty`] function.
19#[derive(Debug, PartialEq, Eq, Clone, Copy)]
20pub struct Empty {
21    _private: (),
22}
23
24impl Row for Empty {
25    #[inline]
26    fn datum_at(&self, index: usize) -> DatumRef<'_> {
27        panic!("index out of bounds: the len of `Empty` is 0 but the index is {index}")
28    }
29
30    #[inline]
31    unsafe fn datum_at_unchecked(&self, _index: usize) -> DatumRef<'_> {
32        // Always ignore the index and return `NULL`, which is okay for undefined behavior.
33        None
34    }
35
36    #[inline]
37    fn len(&self) -> usize {
38        0
39    }
40
41    #[inline]
42    fn iter(&self) -> impl ExactSizeIterator<Item = DatumRef<'_>> {
43        std::iter::empty()
44    }
45}
46
47/// Creates a row which contains no datums.
48pub const fn empty() -> Empty {
49    assert_row(Empty { _private: () })
50}
51
52pub(super) static EMPTY: Empty = empty();