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

facet-rs / facet / 15200164445

23 May 2025 01:21AM UTC coverage: 57.288% (+0.1%) from 57.185%
15200164445

Pull #666

github

web-flow
Merge 4232978c5 into 4b41e5c8a
Pull Request #666: Add indirection to vtable fns to fix cyclic types

715 of 1482 new or added lines in 34 files covered. (48.25%)

14 existing lines in 5 files now uncovered.

9747 of 17014 relevant lines covered (57.29%)

132.73 hits per line

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

67.86
/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| {
96✔
12
                if let Some(opts) = opts.for_children() {
96✔
13
                    write!(f, "[")?;
96✔
14
                    (T::SHAPE.vtable.type_name)(f, opts)?;
96✔
15
                    write!(f, "; {L}]")
96✔
16
                } else {
17
                    write!(f, "[⋯; {L}]")
×
18
                }
19
            })
96✔
20
            .display(|| {
20✔
21
                if (T::SHAPE.vtable.display)().is_some() {
20✔
22
                    Some(|value, f| {
10✔
23
                        write!(f, "[")?;
10✔
24

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

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

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