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

facet-rs / facet / 14948293385

10 May 2025 07:04PM UTC coverage: 57.937% (+0.2%) from 57.742%
14948293385

push

github

fasterthanlime
Introduce as_mut_ptr, fix array tests under miri

6 of 35 new or added lines in 7 files covered. (17.14%)

371 existing lines in 4 files now uncovered.

8639 of 14911 relevant lines covered (57.94%)

122.51 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 {
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
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
/// 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 {
×
NEW
121
        Self {
×
NEW
122
            as_ptr_fn: None,
×
NEW
123
            as_mut_ptr_fn: None,
×
NEW
124
        }
×
UNCOV
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
NEW
134
    pub const fn as_mut_ptr(mut self, f: ArrayAsMutPtrFn) -> Self {
×
NEW
135
        self.as_mut_ptr_fn = Some(f);
×
NEW
136
        self
×
NEW
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(),
×
NEW
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