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

facet-rs / facet / 14546339941

19 Apr 2025 06:02AM UTC coverage: 43.858% (+0.2%) from 43.653%
14546339941

Pull #301

github

web-flow
Merge 7525b4cce into 4c26162f7
Pull Request #301: feat(json) Better error messages when a field is missing

20 of 41 new or added lines in 3 files covered. (48.78%)

1 existing line in 1 file now uncovered.

4813 of 10974 relevant lines covered (43.86%)

49.52 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::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 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
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 {
×
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)]
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: fn() -> &'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 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: PtrConst, index: usize) -> PtrConst;
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
98
    pub const fn builder() -> ArrayVTableBuilder {
×
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)]
111
    pub const fn new() -> Self {
×
112
        Self { get_item_ptr: None }
×
113
    }
×
114

115
    /// Sets the get_item_ptr field
116
    pub const fn get_item_ptr(mut self, f: ArrayGetItemPtrFn) -> Self {
×
117
        self.get_item_ptr = Some(f);
×
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`.
126
    pub const fn build(self) -> ArrayVTable {
×
127
        ArrayVTable {
×
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

© 2025 Coveralls, Inc