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

facet-rs / facet / 14453009436

14 Apr 2025 06:30PM UTC coverage: 29.706% (+3.1%) from 26.594%
14453009436

Pull #213

github

web-flow
Merge 6304b843f into 22eba315a
Pull Request #213: Split `Array` and `Slice` out of `List`, allow more type recursion

241 of 649 new or added lines in 14 files covered. (37.13%)

2 existing lines in 2 files now uncovered.

1938 of 6524 relevant lines covered (29.71%)

25.46 hits per line

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

0.0
/facet-core/src/types/array.rs
1
use crate::opaque::OpaqueConst;
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 {
10
    /// vtable for interacting with the array
11
    pub vtable: &'static ArrayVTable,
12

13
    /// shape of the items in the list
14
    pub t: fn() -> &'static Shape,
15

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

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

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

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

39
impl ArrayDefBuilder {
40
    /// Creates a new ArrayDefBuilder
41
    #[allow(clippy::new_without_default)]
NEW
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: &'static ArrayVTable) -> Self {
×
NEW
52
        self.vtable = Some(vtable);
×
NEW
53
        self
×
54
    }
55

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

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

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

78
/// Get pointer to the item at the given index. Panics if out of bounds.
79
///
80
/// # Safety
81
///
82
/// The `array` parameter must point to aligned, initialized memory of the correct type.
83
pub type ArrayGetItemPtrFn = unsafe fn(array: OpaqueConst, index: usize) -> OpaqueConst;
84

85
/// Virtual table for a list-like type (like `Vec<T>`,
86
/// but also `HashSet<T>`, etc.)
87
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
88
#[repr(C)]
89
#[non_exhaustive]
90
pub struct ArrayVTable {
91
    /// cf. [`ArrayGetItemPtrFn`]
92
    pub get_item_ptr: ArrayGetItemPtrFn,
93
    // TODO: mutation
94
}
95

96
impl ArrayVTable {
97
    /// Returns a builder for ListVTable
NEW
98
    pub const fn builder() -> ArrayVTableBuilder {
×
NEW
99
        ArrayVTableBuilder::new()
×
100
    }
101
}
102

103
/// Builds a [`ArrayVTable`]
104
pub struct ArrayVTableBuilder {
105
    get_item_ptr: Option<ArrayGetItemPtrFn>,
106
}
107

108
impl ArrayVTableBuilder {
109
    /// Creates a new [`ArrayVTableBuilder`] with all fields set to `None`.
110
    #[allow(clippy::new_without_default)]
NEW
111
    pub const fn new() -> Self {
×
112
        Self { get_item_ptr: None }
113
    }
114

115
    /// Sets the get_item_ptr field
NEW
116
    pub const fn get_item_ptr(mut self, f: ArrayGetItemPtrFn) -> Self {
×
NEW
117
        self.get_item_ptr = Some(f);
×
NEW
118
        self
×
119
    }
120

121
    /// Builds the [`ArrayVTable`] from the current state of the builder.
122
    ///
123
    /// # Panics
124
    ///
125
    /// This method will panic if any of the required fields are `None`.
NEW
126
    pub const fn build(self) -> ArrayVTable {
×
127
        ArrayVTable {
NEW
128
            get_item_ptr: self.get_item_ptr.unwrap(),
×
129
        }
130
    }
131
}
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