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

facet-rs / facet / 14931971708

09 May 2025 03:08PM UTC coverage: 55.308%. First build
14931971708

Pull #527

github

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

1077 of 1985 new or added lines in 50 files covered. (54.26%)

6669 of 12058 relevant lines covered (55.31%)

73.99 hits per line

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

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

24
                for (idx, value) in value.iter().enumerate() {
74✔
25
                    (<VTableView<T>>::of().display().unwrap())(value, f)?;
74✔
26
                    if idx != L - 1 {
74✔
27
                        write!(f, ", ")?;
66✔
28
                    }
8✔
29
                }
30
                write!(f, "]")
10✔
31
            });
10✔
32
        }
33
        if T::SHAPE.vtable.debug.is_some() {
34
            builder = builder.debug(|value, f| {
34✔
35
                write!(f, "[")?;
34✔
36

37
                for (idx, value) in value.iter().enumerate() {
226✔
38
                    (<VTableView<T>>::of().debug().unwrap())(value, f)?;
226✔
39
                    if idx != L - 1 {
226✔
40
                        write!(f, ", ")?;
199✔
41
                    }
27✔
42
                }
43
                write!(f, "]")
34✔
44
            });
34✔
45
        }
46
        if T::SHAPE.vtable.eq.is_some() {
47
            builder = builder
48
                .eq(|a, b| zip(a, b).all(|(a, b)| (<VTableView<T>>::of().eq().unwrap())(a, b)));
37✔
49
        }
50
        if L == 0 {
51
            // Zero-length arrays implement `Default` irrespective of the element type
52
            builder = builder.default_in_place(|target| unsafe { target.assume_init() });
1✔
53
        } else if L <= 32 && T::SHAPE.vtable.default_in_place.is_some() {
54
            builder = builder.default_in_place(|mut target| unsafe {
3✔
55
                let t_dip = <VTableView<T>>::of().default_in_place().unwrap();
3✔
56
                let stride = T::SHAPE
3✔
57
                    .layout
3✔
58
                    .sized_layout()
3✔
59
                    .unwrap()
3✔
60
                    .pad_to_align()
3✔
61
                    .size();
3✔
62
                for idx in 0..L {
7✔
63
                    t_dip(target.field_uninit_at(idx * stride));
4✔
64
                }
4✔
65
                target.assume_init()
3✔
66
            });
3✔
67
        } else {
68
            // arrays do not yet implement `Default` for > 32 elements due to
69
            // specializing the `0` len case
70
        }
71
        if T::SHAPE.vtable.clone_into.is_some() {
NEW
72
            builder = builder.clone_into(|src, mut dst| unsafe {
×
NEW
73
                let t_cip = <VTableView<T>>::of().clone_into().unwrap();
×
NEW
74
                let stride = T::SHAPE
×
NEW
75
                    .layout
×
NEW
76
                    .sized_layout()
×
NEW
77
                    .unwrap()
×
NEW
78
                    .pad_to_align()
×
NEW
79
                    .size();
×
NEW
80
                for (idx, src) in src.iter().enumerate() {
×
NEW
81
                    (t_cip)(src, dst.field_uninit_at(idx * stride));
×
NEW
82
                }
×
NEW
83
                dst.assume_init()
×
NEW
84
            });
×
85
        }
86
        if T::SHAPE.vtable.partial_ord.is_some() {
87
            builder = builder.partial_ord(|a, b| {
5✔
88
                zip(a, b)
5✔
89
                    .find_map(
5✔
90
                        |(a, b)| match (<VTableView<T>>::of().partial_ord().unwrap())(a, b) {
37✔
91
                            Some(Ordering::Equal) => None,
34✔
92
                            c => Some(c),
3✔
93
                        },
37✔
94
                    )
95
                    .unwrap_or(Some(Ordering::Equal))
5✔
96
            });
5✔
97
        }
98
        if T::SHAPE.vtable.ord.is_some() {
NEW
99
            builder = builder.ord(|a, b| {
×
NEW
100
                zip(a, b)
×
NEW
101
                    .find_map(
×
NEW
102
                        |(a, b)| match (<VTableView<T>>::of().ord().unwrap())(a, b) {
×
NEW
103
                            Ordering::Equal => None,
×
NEW
104
                            c => Some(c),
×
NEW
105
                        },
×
106
                    )
NEW
107
                    .unwrap_or(Ordering::Equal)
×
NEW
108
            });
×
109
        }
110
        if T::SHAPE.vtable.hash.is_some() {
NEW
111
            builder = builder.hash(|value, state, hasher| {
×
NEW
112
                for value in value {
×
NEW
113
                    (<VTableView<T>>::of().hash().unwrap())(value, state, hasher)
×
114
                }
NEW
115
            });
×
116
        }
117
        builder.build()
118
    };
119

120
    const SHAPE: &'static Shape = &const {
121
        Shape::builder_for_sized::<Self>()
122
            .type_params(&[TypeParam {
123
                name: "T",
124
                shape: || T::SHAPE,
1✔
125
            }])
126
            .ty(Type::Sequence(SequenceType::Array(ArrayType {
127
                t: T::SHAPE,
128
                n: L,
129
            })))
130
            .def(Def::Array(
131
                ArrayDef::builder()
132
                    .vtable(
133
                        &const {
134
                            ArrayVTable::builder()
135
                                .as_ptr(|ptr| unsafe {
3✔
136
                                    let array = ptr.get::<[T; L]>();
3✔
137
                                    PtrConst::new(array.as_ptr())
3✔
138
                                })
3✔
139
                                .build()
140
                        },
141
                    )
142
                    .t(T::SHAPE)
143
                    .n(L)
144
                    .build(),
145
            ))
146
            .build()
147
    };
148
}
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