• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16728097825

04 Aug 2025 04:00PM UTC coverage: 48.355% (-35.1%) from 83.429%
16728097825

Pull #4108

github

web-flow
Merge 1b2d27fd8 into 649ba9576
Pull Request #4108: perf[vortex-array]: use all_valid instead of `invalid_count() == 0`

1 of 1 new or added line in 1 file covered. (100.0%)

11596 existing lines in 378 files now uncovered.

18635 of 38538 relevant lines covered (48.35%)

151786.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.88
/vortex-buffer/src/const.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::ops::Deref;
5

6
use vortex_error::{VortexError, vortex_bail};
7

8
use crate::{Alignment, Buffer};
9

10
/// A buffer of items of `T` with a compile-time alignment.
11
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Hash)]
12
pub struct ConstBuffer<T, const A: usize>(Buffer<T>);
13

14
impl<T, const A: usize> ConstBuffer<T, A> {
15
    /// Returns the alignment of the buffer.
16
    pub const fn alignment() -> Alignment {
5,030✔
17
        Alignment::new(A)
5,030✔
18
    }
5,030✔
19

20
    /// Align the given buffer (possibly with a copy) and return a new `ConstBuffer`.
21
    pub fn align_from<B: Into<Buffer<T>>>(buf: B) -> Self {
3,562✔
22
        Self(buf.into().aligned(Self::alignment()))
3,562✔
23
    }
3,562✔
24

25
    /// Create a new [`ConstBuffer`] with a copy from the provided slice.
26
    pub fn copy_from<B: AsRef<[T]>>(buf: B) -> Self {
128✔
27
        Self(Buffer::<T>::copy_from_aligned(buf, Self::alignment()))
128✔
28
    }
128✔
29

30
    /// Returns a slice over the buffer of elements of type T.
31
    #[inline(always)]
32
    pub fn as_slice(&self) -> &[T] {
×
33
        self.0.as_slice()
×
34
    }
×
35

36
    /// Unwrap the inner buffer.
37
    pub fn inner(&self) -> &Buffer<T> {
×
38
        &self.0
×
39
    }
×
40

41
    /// Unwrap the inner buffer.
UNCOV
42
    pub fn into_inner(self) -> Buffer<T> {
×
UNCOV
43
        self.0
×
UNCOV
44
    }
×
45
}
46

47
impl<T, const A: usize> TryFrom<Buffer<T>> for ConstBuffer<T, A> {
48
    type Error = VortexError;
49

UNCOV
50
    fn try_from(value: Buffer<T>) -> Result<Self, Self::Error> {
×
UNCOV
51
        if !value.alignment().is_aligned_to(Alignment::new(A)) {
×
52
            vortex_bail!(
×
53
                "Cannot convert buffer with alignment {} to buffer with alignment {}",
×
54
                value.alignment(),
×
55
                A
56
            );
UNCOV
57
        }
×
UNCOV
58
        Ok(Self(value))
×
UNCOV
59
    }
×
60
}
61

62
impl<T, const A: usize> AsRef<Buffer<T>> for ConstBuffer<T, A> {
63
    fn as_ref(&self) -> &Buffer<T> {
135,000✔
64
        &self.0
135,000✔
65
    }
135,000✔
66
}
67

68
impl<T, const A: usize> Deref for ConstBuffer<T, A> {
69
    type Target = [T];
70

71
    fn deref(&self) -> &Self::Target {
160✔
72
        self.0.as_slice()
160✔
73
    }
160✔
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc