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

facet-rs / facet / 19992197531

06 Dec 2025 05:58PM UTC coverage: 58.742% (-0.005%) from 58.747%
19992197531

Pull #1118

github

web-flow
Merge 9a6a630f8 into 45a8cb1c3
Pull Request #1118: Reduce/cordon bloat in facet, introduce bloatbench

1142 of 3107 new or added lines in 61 files covered. (36.76%)

533 existing lines in 29 files now uncovered.

24225 of 41240 relevant lines covered (58.74%)

502.48 hits per line

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

46.0
/facet-core/src/impls_alloc/vec.rs
1
use core::ptr::NonNull;
2

3
use crate::shape_util::vtable_for_list;
4
use crate::*;
5

6
use alloc::boxed::Box;
7
use alloc::vec::Vec;
8

9
type VecIterator<'mem, T> = core::slice::Iter<'mem, T>;
10

11
unsafe impl<'a, T> Facet<'a> for Vec<T>
12
where
13
    T: Facet<'a>,
14
{
15
    const SHAPE: &'static Shape = &const {
16
        Shape {
17
            id: Shape::id_of::<Self>(),
18
            layout: Shape::layout_of::<Self>(),
19
            vtable: ValueVTable {
20
                type_name: |f, opts| {
206✔
21
                    if let Some(opts) = opts.for_children() {
206✔
22
                        write!(f, "{}<", Self::SHAPE.type_identifier)?;
206✔
23
                        T::SHAPE.vtable.type_name()(f, opts)?;
206✔
24
                        write!(f, ">")
206✔
25
                    } else {
NEW
26
                        write!(f, "{}<…>", Self::SHAPE.type_identifier)
×
27
                    }
28
                },
206✔
29
                default_in_place: Some(|target| unsafe { target.put(Self::default()) }),
2✔
30
                ..vtable_for_list::<T, Self>()
31
            },
32
            ty: Type::User(UserType::Opaque),
33
            def: Def::List(ListDef::new(
34
                &const {
35
                    ListVTable {
36
                        init_in_place_with_capacity: Some(|data, capacity| unsafe {
37
                            data.put(Self::with_capacity(capacity))
235✔
38
                        }),
235✔
39
                        push: Some(|ptr, item| unsafe {
40
                            let vec = ptr.as_mut::<Self>();
12,773✔
41
                            let item = item.read::<T>();
12,773✔
42
                            (*vec).push(item);
12,773✔
43
                        }),
12,773✔
44
                        len: |ptr| unsafe {
45
                            let vec = ptr.get::<Self>();
219✔
46
                            vec.len()
219✔
47
                        },
219✔
48
                        get: |ptr, index| unsafe {
49
                            let vec = ptr.get::<Self>();
26✔
50
                            let item = vec.get(index)?;
26✔
51
                            Some(PtrConst::new(NonNull::from(item)))
24✔
52
                        },
26✔
53
                        get_mut: Some(|ptr, index| unsafe {
NEW
54
                            let vec = ptr.as_mut::<Self>();
×
NEW
55
                            let item = vec.get_mut(index)?;
×
NEW
56
                            Some(PtrMut::new(NonNull::from(item)))
×
NEW
57
                        }),
×
58
                        as_ptr: Some(|ptr| unsafe {
59
                            let vec = ptr.get::<Self>();
151✔
60
                            PtrConst::new(NonNull::new_unchecked(vec.as_ptr() as *mut T))
151✔
61
                        }),
151✔
62
                        as_mut_ptr: Some(|ptr| unsafe {
NEW
63
                            let vec = ptr.as_mut::<Self>();
×
NEW
64
                            PtrMut::new(NonNull::new_unchecked(vec.as_mut_ptr()))
×
NEW
65
                        }),
×
66
                        iter_vtable: {
67
                            IterVTable {
68
                                init_with_value: Some(|ptr| unsafe {
UNCOV
69
                                    let vec = ptr.get::<Self>();
×
NEW
70
                                    let iter: VecIterator<T> = vec.iter();
×
NEW
71
                                    let iter_state = Box::new(iter);
×
NEW
72
                                    PtrMut::new(NonNull::new_unchecked(
×
NEW
73
                                        Box::into_raw(iter_state) as *mut u8
×
74
                                    ))
NEW
75
                                }),
×
76
                                next: |iter_ptr| unsafe {
NEW
77
                                    let state = iter_ptr.as_mut::<VecIterator<'_, T>>();
×
NEW
78
                                    state
×
NEW
79
                                        .next()
×
NEW
80
                                        .map(|value| PtrConst::new(NonNull::from(value)))
×
NEW
81
                                },
×
82
                                next_back: Some(|iter_ptr| unsafe {
NEW
83
                                    let state = iter_ptr.as_mut::<VecIterator<'_, T>>();
×
NEW
84
                                    state
×
NEW
85
                                        .next_back()
×
NEW
86
                                        .map(|value| PtrConst::new(NonNull::from(value)))
×
NEW
87
                                }),
×
88
                                size_hint: None,
89
                                dealloc: |iter_ptr| unsafe {
NEW
90
                                    drop(Box::from_raw(iter_ptr.as_ptr::<VecIterator<'_, T>>()
×
NEW
91
                                        as *mut VecIterator<'_, T>));
×
NEW
92
                                },
×
93
                            }
94
                        },
95
                    }
96
                },
97
                T::SHAPE,
98
            )),
99
            type_identifier: "Vec",
100
            type_params: &[TypeParam {
101
                name: "T",
102
                shape: T::SHAPE,
103
            }],
104
            doc: &[],
105
            attributes: &[],
106
            type_tag: None,
107
            inner: None,
108
        }
109
    };
110
}
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