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

facet-rs / facet / 14926687950

09 May 2025 10:14AM UTC coverage: 46.806%. First build
14926687950

Pull #527

github

web-flow
Merge 3b18cb24f into a46b975f2
Pull Request #527: Rework type information (Def) — rebased #462

684 of 1486 new or added lines in 48 files covered. (46.03%)

5187 of 11082 relevant lines covered (46.81%)

29.7 hits per line

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

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

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

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

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

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

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

39
impl ArrayDefBuilder {
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
51
    pub const fn vtable(mut self, vtable: &'static 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: &'static 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
69
    pub const fn build(self) -> ArrayDef {
×
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
/// Virtual table for an array
86
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
87
#[repr(C)]
88
#[non_exhaustive]
89
pub struct ArrayVTable {
90
    /// cf. [`ArrayAsPtrFn`]
91
    pub as_ptr: ArrayAsPtrFn,
92
}
93

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

101
/// Builds a [`ArrayVTable`]
102
pub struct ArrayVTableBuilder {
103
    as_ptr_fn: Option<ArrayAsPtrFn>,
104
}
105

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

113
    /// Sets the as_ptr field
NEW
114
    pub const fn as_ptr(mut self, f: ArrayAsPtrFn) -> Self {
×
NEW
115
        self.as_ptr_fn = Some(f);
×
116
        self
×
117
    }
×
118

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