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

facet-rs / facet / 15085921060

17 May 2025 02:00PM UTC coverage: 56.937% (+0.2%) from 56.732%
15085921060

push

github

fasterthanlime
Introduce `'shape` lifetime, allowing non-'static shapes.

Closes #455.

402 of 615 new or added lines in 70 files covered. (65.37%)

31 existing lines in 3 files now uncovered.

9176 of 16116 relevant lines covered (56.94%)

126.52 hits per line

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

5.45
/facet-core/src/types/def/array.rs
1
use crate::{PtrMut, ptr::PtrConst};
2

3
use super::Shape;
4

5
/// Fields for array types
6
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7
#[repr(C)]
8
#[non_exhaustive]
9
pub struct ArrayDef<'shape> {
10
    /// vtable for interacting with the array
11
    pub vtable: &'shape ArrayVTable,
12

13
    /// shape of the items in the array
14
    pub t: &'shape Shape<'shape>,
15

16
    /// The length of the array
17
    pub n: usize,
18
}
19

20
impl<'shape> ArrayDef<'shape> {
21
    /// Returns a builder for ArrayDef
NEW
22
    pub const fn builder() -> ArrayDefBuilder<'shape> {
×
23
        ArrayDefBuilder::new()
×
24
    }
×
25

26
    /// Returns the shape of the items in the array
27
    pub fn t(&self) -> &'shape Shape<'shape> {
7✔
28
        self.t
7✔
29
    }
7✔
30
}
31

32
/// Builder for ArrayDef
33
pub struct ArrayDefBuilder<'shape> {
34
    vtable: Option<&'shape ArrayVTable>,
35
    t: Option<&'shape Shape<'shape>>,
36
    n: Option<usize>,
37
}
38

39
impl<'shape> ArrayDefBuilder<'shape> {
40
    /// Creates a new ArrayDefBuilder
41
    #[allow(clippy::new_without_default)]
42
    pub const fn new() -> Self {
×
43
        Self {
×
44
            vtable: None,
×
45
            t: None,
×
46
            n: None,
×
47
        }
×
48
    }
×
49

50
    /// Sets the vtable for the ArrayDef
NEW
51
    pub const fn vtable(mut self, vtable: &'shape ArrayVTable) -> Self {
×
52
        self.vtable = Some(vtable);
×
53
        self
×
54
    }
×
55

56
    /// Sets the item shape for the ArrayDef
NEW
57
    pub const fn t(mut self, t: &'shape Shape<'shape>) -> Self {
×
58
        self.t = Some(t);
×
59
        self
×
60
    }
×
61

62
    /// Sets the length for the ArrayDef (added method)
63
    pub const fn n(mut self, n: usize) -> Self {
×
64
        self.n = Some(n);
×
65
        self
×
66
    }
×
67

68
    /// Builds the ArrayDef
NEW
69
    pub const fn build(self) -> ArrayDef<'shape> {
×
70
        ArrayDef {
×
71
            vtable: self.vtable.unwrap(),
×
72
            t: self.t.unwrap(),
×
73
            n: self.n.unwrap(),
×
74
        }
×
75
    }
×
76
}
77

78
/// Get pointer to the data buffer of the array.
79
///
80
/// # Safety
81
///
82
/// The `array` parameter must point to aligned, initialized memory of the correct type.
83
pub type ArrayAsPtrFn = unsafe fn(array: PtrConst) -> PtrConst;
84

85
/// Get mutable pointer to the data buffer of the array.
86
///
87
/// # Safety
88
///
89
/// The `array` parameter must point to aligned, initialized memory of the correct type.
90
pub type ArrayAsMutPtrFn = unsafe fn(array: PtrMut) -> PtrMut;
91

92
/// Virtual table for an array
93
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
94
#[repr(C)]
95
#[non_exhaustive]
96
pub struct ArrayVTable {
97
    /// cf. [`ArrayAsPtrFn`]
98
    pub as_ptr: ArrayAsPtrFn,
99

100
    /// cf. [`ArrayAsMutPtrFn`]
101
    pub as_mut_ptr: ArrayAsMutPtrFn,
102
}
103

104
impl ArrayVTable {
105
    /// Returns a builder for ListVTable
106
    pub const fn builder() -> ArrayVTableBuilder {
×
107
        ArrayVTableBuilder::new()
×
108
    }
×
109
}
110

111
/// Builds a [`ArrayVTable`]
112
pub struct ArrayVTableBuilder {
113
    as_ptr_fn: Option<ArrayAsPtrFn>,
114
    as_mut_ptr_fn: Option<ArrayAsMutPtrFn>,
115
}
116

117
impl ArrayVTableBuilder {
118
    /// Creates a new [`ArrayVTableBuilder`] with all fields set to `None`.
119
    #[allow(clippy::new_without_default)]
120
    pub const fn new() -> Self {
×
121
        Self {
×
122
            as_ptr_fn: None,
×
123
            as_mut_ptr_fn: None,
×
124
        }
×
125
    }
×
126

127
    /// Sets the as_ptr field
128
    pub const fn as_ptr(mut self, f: ArrayAsPtrFn) -> Self {
×
129
        self.as_ptr_fn = Some(f);
×
130
        self
×
131
    }
×
132

133
    /// Sets the as_mut_ptr field
134
    pub const fn as_mut_ptr(mut self, f: ArrayAsMutPtrFn) -> Self {
×
135
        self.as_mut_ptr_fn = Some(f);
×
136
        self
×
137
    }
×
138

139
    /// Builds the [`ArrayVTable`] from the current state of the builder.
140
    ///
141
    /// # Panics
142
    ///
143
    /// This method will panic if any of the required fields are `None`.
144
    pub const fn build(self) -> ArrayVTable {
×
145
        ArrayVTable {
×
146
            as_ptr: self.as_ptr_fn.unwrap(),
×
147
            as_mut_ptr: self.as_mut_ptr_fn.unwrap(),
×
148
        }
×
149
    }
×
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc