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

facet-rs / facet / 15377025676

01 Jun 2025 04:15PM UTC coverage: 58.697% (+0.6%) from 58.142%
15377025676

Pull #700

github

web-flow
Merge dc1a9beb4 into 0530f47a7
Pull Request #700: Solve code comment inconsistencies and add missing validations

0 of 2 new or added lines in 2 files covered. (0.0%)

2083 existing lines in 47 files now uncovered.

10306 of 17558 relevant lines covered (58.7%)

128.69 hits per line

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

84.21
/facet-core/src/impls_core/array.rs
1
use crate::*;
2
use core::{cmp::Ordering, iter::zip};
3

4
unsafe impl<'a, T, const L: usize> Facet<'a> for [T; L]
5
where
6
    T: Facet<'a>,
7
{
8
    const VTABLE: &'static ValueVTable = &const {
9
        ValueVTable::builder::<Self>()
10
            .marker_traits(T::SHAPE.vtable.marker_traits)
11
            .type_name(|f, opts| {
98✔
12
                if let Some(opts) = opts.for_children() {
98✔
13
                    write!(f, "[")?;
98✔
14
                    (T::SHAPE.vtable.type_name)(f, opts)?;
98✔
15
                    write!(f, "; {L}]")
98✔
16
                } else {
17
                    write!(f, "[⋯; {L}]")
×
18
                }
19
            })
98✔
20
            .display(|| {
48✔
21
                if (T::SHAPE.vtable.display)().is_some() {
48✔
22
                    Some(|value, f| {
28✔
23
                        write!(f, "[")?;
28✔
24

25
                        for (idx, value) in value.iter().enumerate() {
188✔
26
                            (<VTableView<T>>::of().display().unwrap())(value, f)?;
188✔
27
                            if idx != L - 1 {
188✔
28
                                write!(f, ", ")?;
166✔
29
                            }
22✔
30
                        }
31
                        write!(f, "]")
28✔
32
                    })
28✔
33
                } else {
34
                    None
×
35
                }
36
            })
48✔
37
            .debug(|| {
93✔
38
                if (T::SHAPE.vtable.debug)().is_some() {
93✔
39
                    Some(|value, f| {
73✔
40
                        write!(f, "[")?;
73✔
41

42
                        for (idx, value) in value.iter().enumerate() {
521✔
43
                            (<VTableView<T>>::of().debug().unwrap())(value, f)?;
521✔
44
                            if idx != L - 1 {
521✔
45
                                write!(f, ", ")?;
463✔
46
                            }
58✔
47
                        }
48
                        write!(f, "]")
73✔
49
                    })
73✔
50
                } else {
51
                    None
×
52
                }
53
            })
93✔
54
            .partial_eq(|| {
20✔
55
                if (T::SHAPE.vtable.partial_eq)().is_some() {
20✔
56
                    Some(|a, b| {
10✔
57
                        zip(a, b).all(|(a, b)| (<VTableView<T>>::of().partial_eq().unwrap())(a, b))
74✔
58
                    })
10✔
59
                } else {
60
                    None
×
61
                }
62
            })
20✔
63
            .default_in_place(|| {
20✔
64
                if L == 0 {
20✔
65
                    // Zero-length arrays implement `Default` irrespective of the element type
66
                    Some(|target| unsafe { target.assume_init() })
2✔
67
                } else if L <= 32 && (T::SHAPE.vtable.default_in_place)().is_some() {
16✔
68
                    Some(|mut target| unsafe {
69
                        let t_dip = <VTableView<T>>::of().default_in_place().unwrap();
4✔
70
                        let stride = T::SHAPE
4✔
71
                            .layout
4✔
72
                            .sized_layout()
4✔
73
                            .unwrap()
4✔
74
                            .pad_to_align()
4✔
75
                            .size();
4✔
76
                        for idx in 0..L {
10✔
77
                            t_dip(target.field_uninit_at(idx * stride));
6✔
78
                        }
6✔
79
                        target.assume_init()
4✔
80
                    })
4✔
81
                } else {
82
                    // arrays do not yet implement `Default` for > 32 elements due
83
                    // to specializing the `0` len case
84
                    None
8✔
85
                }
86
            })
20✔
87
            .clone_into(|| {
20✔
88
                if (T::SHAPE.vtable.clone_into)().is_some() {
20✔
89
                    Some(|src, mut dst| unsafe {
90
                        let t_cip = <VTableView<T>>::of().clone_into().unwrap();
5✔
91
                        let stride = T::SHAPE
5✔
92
                            .layout
5✔
93
                            .sized_layout()
5✔
94
                            .unwrap()
5✔
95
                            .pad_to_align()
5✔
96
                            .size();
5✔
97
                        for (idx, src) in src.iter().enumerate() {
37✔
98
                            (t_cip)(src, dst.field_uninit_at(idx * stride));
37✔
99
                        }
37✔
100
                        dst.assume_init()
5✔
101
                    })
5✔
102
                } else {
103
                    None
×
104
                }
105
            })
20✔
106
            .partial_ord(|| {
15✔
107
                if (T::SHAPE.vtable.partial_ord)().is_some() {
15✔
108
                    Some(|a, b| {
10✔
109
                        zip(a, b)
10✔
110
                            .find_map(|(a, b)| {
74✔
111
                                match (<VTableView<T>>::of().partial_ord().unwrap())(a, b) {
74✔
112
                                    Some(Ordering::Equal) => None,
68✔
113
                                    c => Some(c),
6✔
114
                                }
115
                            })
74✔
116
                            .unwrap_or(Some(Ordering::Equal))
10✔
117
                    })
10✔
118
                } else {
119
                    // arrays do not yet implement `Default` for > 32 elements due
120
                    // to specializing the `0` len case
121
                    None
×
122
                }
123
            })
15✔
124
            .ord(|| {
15✔
125
                if (T::SHAPE.vtable.ord)().is_some() {
15✔
126
                    Some(|a, b| {
5✔
127
                        zip(a, b)
5✔
128
                            .find_map(
5✔
129
                                |(a, b)| match (<VTableView<T>>::of().ord().unwrap())(a, b) {
37✔
130
                                    Ordering::Equal => None,
34✔
131
                                    c => Some(c),
3✔
132
                                },
37✔
133
                            )
134
                            .unwrap_or(Ordering::Equal)
5✔
135
                    })
5✔
136
                } else {
137
                    // arrays do not yet implement `Default` for > 32 elements due
138
                    // to specializing the `0` len case
139
                    None
×
140
                }
141
            })
15✔
142
            .hash(|| {
×
143
                if (T::SHAPE.vtable.hash)().is_some() {
×
144
                    Some(|value, state, hasher| {
×
145
                        for value in value {
×
146
                            (<VTableView<T>>::of().hash().unwrap())(value, state, hasher)
×
147
                        }
148
                    })
×
149
                } else {
150
                    // arrays do not yet implement `Default` for > 32 elements due
151
                    // to specializing the `0` len case
152
                    None
×
153
                }
154
            })
×
155
            .build()
156
    };
157

158
    const SHAPE: &'static Shape<'static> = &const {
159
        Shape::builder_for_sized::<Self>()
160
            .type_identifier("&[_; _]")
161
            .type_params(&[TypeParam {
162
                name: "T",
163
                shape: || T::SHAPE,
164
            }])
165
            .ty(Type::Sequence(SequenceType::Array(ArrayType {
166
                t: T::SHAPE,
167
                n: L,
168
            })))
169
            .def(Def::Array(
170
                ArrayDef::builder()
171
                    .vtable(
172
                        &const {
173
                            ArrayVTable::builder()
174
                                .as_ptr(|ptr| unsafe {
175
                                    let array = ptr.get::<[T; L]>();
3✔
176
                                    PtrConst::new(array.as_ptr())
3✔
177
                                })
3✔
178
                                .as_mut_ptr(|ptr| unsafe {
UNCOV
179
                                    let array = ptr.as_mut::<[T; L]>();
×
UNCOV
180
                                    PtrMut::new(array.as_mut_ptr())
×
UNCOV
181
                                })
×
182
                                .build()
183
                        },
184
                    )
185
                    .t(T::SHAPE)
186
                    .n(L)
187
                    .build(),
188
            ))
189
            .build()
190
    };
191
}
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