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

facet-rs / facet / 14490918692

16 Apr 2025 10:47AM UTC coverage: 41.767% (+0.3%) from 41.467%
14490918692

push

github

fasterthanlime
Expose generic type params in derive

Closes #192

27 of 27 new or added lines in 3 files covered. (100.0%)

226 existing lines in 12 files now uncovered.

4490 of 10750 relevant lines covered (41.77%)

55.42 hits per line

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

73.91
/facet-core/src/impls_alloc/vec.rs
1
use crate::*;
2
use core::{alloc::Layout, hash::Hash as _};
3

4
use alloc::vec::Vec;
5

6
unsafe impl<T> Facet for Vec<T>
7
where
8
    T: Facet,
9
{
10
    const SHAPE: &'static Shape = &const {
11
        Shape::builder()
12
            .id(ConstTypeId::of::<Vec<T>>())
13
            .layout(Layout::new::<Vec<T>>())
14
            .type_params(&[
15
                TypeParam {
16
                    name: "T",
17
                    shape: || T::SHAPE,
1✔
18
                }
19
            ])
20
            .vtable(
21
                &const {
22
                    let mut builder = ValueVTable::builder()
23
                        .type_name(|f, opts| {
285✔
24
                            if let Some(opts) = opts.for_children() {
285✔
25
                                write!(f, "Vec<")?;
285✔
26
                                (T::SHAPE.vtable.type_name)(f, opts)?;
285✔
27
                                write!(f, ">")
285✔
28
                            } else {
UNCOV
29
                                write!(f, "Vec<⋯>")
×
30
                            }
31
                        })
285✔
32
                        .drop_in_place(|value| unsafe { value.drop_in_place::<Vec<T>>() })
14✔
33
                        .default_in_place(|target| unsafe { target.put(Self::default()) })
33✔
UNCOV
34
                        .clone_into(|src, dst| unsafe { dst.put(src.get::<Vec<T>>()) });
×
35

36
                    if T::SHAPE.vtable.debug.is_some() {
37
                        builder = builder.debug(|value, f| {
5✔
38
                            let value = unsafe { value.get::<Vec<T>>() };
5✔
39
                            write!(f, "[")?;
5✔
40
                            for (i, item) in value.iter().enumerate() {
12✔
41
                                if i > 0 {
12✔
42
                                    write!(f, ", ")?;
8✔
43
                                }
4✔
44
                                unsafe {
45
                                    (T::SHAPE.vtable.debug.unwrap_unchecked())(
12✔
46
                                        PtrConst::new(item),
12✔
47
                                        f,
12✔
48
                                    )?;
12✔
49
                                }
50
                            }
51
                            write!(f, "]")
5✔
52
                        });
5✔
53
                    }
54

55
                    if T::SHAPE.vtable.eq.is_some() {
56
                        builder = builder.eq(|a, b| unsafe {
1✔
57
                            let a = a.get::<Vec<T>>();
1✔
58
                            let b = b.get::<Vec<T>>();
1✔
59
                            if a.len() != b.len() {
1✔
UNCOV
60
                                return false;
×
61
                            }
1✔
62
                            for (item_a, item_b) in a.iter().zip(b.iter()) {
1✔
63
                                if !(T::SHAPE.vtable.eq.unwrap_unchecked())(
1✔
64
                                    PtrConst::new(item_a),
1✔
65
                                    PtrConst::new(item_b),
1✔
66
                                ) {
1✔
67
                                    return false;
1✔
UNCOV
68
                                }
×
69
                            }
UNCOV
70
                            true
×
71
                        });
1✔
72
                    }
73

74
                    if T::SHAPE.vtable.hash.is_some() {
75
                        builder = builder.hash(|value, hasher_this, hasher_write_fn| unsafe {
76
                            use crate::HasherProxy;
77
                            let vec = value.get::<Vec<T>>();
×
78
                            let t_hash = T::SHAPE.vtable.hash.unwrap_unchecked();
×
UNCOV
79
                            let mut hasher = HasherProxy::new(hasher_this, hasher_write_fn);
×
UNCOV
80
                            vec.len().hash(&mut hasher);
×
UNCOV
81
                            for item in vec {
×
UNCOV
82
                                (t_hash)(PtrConst::new(item), hasher_this, hasher_write_fn);
×
UNCOV
83
                            }
×
UNCOV
84
                        });
×
85
                    }
86

87
                    let traits = MarkerTraits::SEND
88
                        .union(MarkerTraits::SYNC)
89
                        .union(MarkerTraits::EQ)
90
                        .union(MarkerTraits::UNPIN)
91
                        .intersection(T::SHAPE.vtable.marker_traits);
92
                    builder = builder.marker_traits(traits);
93

94
                    builder.build()
95
                },
96
            )
97
            .def(Def::List(
98
                ListDef::builder()
99
                    .vtable(
100
                        &const {
101
                            ListVTable::builder()
UNCOV
102
                                .init_in_place_with_capacity(|data, capacity| unsafe {
×
UNCOV
103
                                    data.put(Self::with_capacity(capacity))
×
UNCOV
104
                                })
×
105
                                .push(|ptr, item| unsafe {
50✔
106
                                    let vec = ptr.as_mut::<Vec<T>>();
50✔
107
                                    let item = item.read::<T>();
50✔
108
                                    (*vec).push(item);
50✔
109
                                })
50✔
110
                                .len(|ptr| unsafe {
10✔
111
                                    let vec = ptr.get::<Vec<T>>();
10✔
112
                                    vec.len()
10✔
113
                                })
10✔
114
                                .get_item_ptr(|ptr, index| unsafe {
6✔
115
                                    let vec = ptr.get::<Vec<T>>();
6✔
116
                                    let len = vec.len();
6✔
117
                                    if index >= len {
6✔
UNCOV
118
                                        panic!(
×
UNCOV
119
                                            "Index out of bounds: the len is {len} but the index is {index}"
×
120
                                        );
121
                                    }
6✔
122
                                    PtrConst::new(vec.as_ptr().add(index))
6✔
123
                                })
6✔
124
                                .build()
125
                        },
126
                    )
127
                    .t(|| T::SHAPE)
62✔
128
                    .build(),
129
            ))
130
            .build()
131
    };
132
}
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