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

facet-rs / facet / 14948265066

10 May 2025 07:02PM UTC coverage: 57.937% (+0.2%) from 57.742%
14948265066

Pull #554

github

web-flow
Merge 4129146b5 into 977647cd8
Pull Request #554: facet-reflect + facet-json: Handle arrays

552 of 768 new or added lines in 12 files covered. (71.88%)

1 existing line in 1 file now uncovered.

8639 of 14911 relevant lines covered (57.94%)

122.52 hits per line

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

76.81
/facet-core/src/impls_alloc/vec.rs
1
use crate::*;
2
use core::hash::Hash as _;
3

4
use alloc::vec::Vec;
5

6
unsafe impl<'a, T> Facet<'a> for Vec<T>
7
where
8
    T: Facet<'a>,
9
{
10
    const VTABLE: &'static ValueVTable = &const {
11
        let mut builder = ValueVTable::builder::<Self>()
12
            .type_name(|f, opts| {
109✔
13
                if let Some(opts) = opts.for_children() {
109✔
14
                    write!(f, "Vec<")?;
109✔
15
                    (T::SHAPE.vtable.type_name)(f, opts)?;
109✔
16
                    write!(f, ">")
109✔
17
                } else {
18
                    write!(f, "Vec<⋯>")
×
19
                }
20
            })
109✔
21
            .default_in_place(|target| unsafe { target.put(Self::default()) });
80✔
22

23
        if T::SHAPE.vtable.clone_into.is_some() {
24
            builder = builder.clone_into(|src, dst| unsafe {
1✔
25
                let mut new_vec = Vec::with_capacity(src.len());
1✔
26

1✔
27
                let t_clone_into = <VTableView<T>>::of().clone_into().unwrap();
1✔
28

29
                for item in src {
2✔
30
                    use crate::TypedPtrUninit;
31
                    use core::mem::MaybeUninit;
32

33
                    let mut new_item = MaybeUninit::<T>::uninit();
1✔
34
                    let uninit_item = TypedPtrUninit::new(new_item.as_mut_ptr());
1✔
35

1✔
36
                    (t_clone_into)(item, uninit_item);
1✔
37

1✔
38
                    new_vec.push(new_item.assume_init());
1✔
39
                }
40

41
                dst.put(new_vec)
1✔
42
            });
1✔
43
        }
44

45
        if T::SHAPE.vtable.debug.is_some() {
46
            builder = builder.debug(|value, f| {
20✔
47
                write!(f, "[")?;
20✔
48
                for (i, item) in value.iter().enumerate() {
40✔
49
                    if i > 0 {
40✔
50
                        write!(f, ", ")?;
24✔
51
                    }
16✔
52
                    (<VTableView<T>>::of().debug().unwrap())(item, f)?;
40✔
53
                }
54
                write!(f, "]")
20✔
55
            });
20✔
56
        }
57

58
        if T::SHAPE.vtable.eq.is_some() {
59
            builder = builder.eq(|a, b| {
4✔
60
                if a.len() != b.len() {
4✔
61
                    return false;
×
62
                }
4✔
63
                for (item_a, item_b) in a.iter().zip(b.iter()) {
7✔
64
                    if !(<VTableView<T>>::of().eq().unwrap())(item_a, item_b) {
7✔
65
                        return false;
2✔
66
                    }
5✔
67
                }
68
                true
2✔
69
            });
4✔
70
        }
71

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

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

91
        builder.build()
92
    };
93

94
    const SHAPE: &'static Shape = &const {
95
        Shape::builder_for_sized::<Self>()
96
            .type_params(&[TypeParam {
97
                name: "T",
98
                shape: || T::SHAPE,
1✔
99
            }])
100
            .ty(Type::User(UserType::Opaque))
101
            .def(Def::List(
102
                ListDef::builder()
103
                    .vtable(
104
                        &const {
105
                            ListVTable::builder()
106
                                .init_in_place_with_capacity(|data, capacity| unsafe {
×
107
                                    data.put(Self::with_capacity(capacity))
×
108
                                })
×
109
                                .push(|ptr, item| unsafe {
99✔
110
                                    let vec = ptr.as_mut::<Self>();
99✔
111
                                    let item = item.read::<T>();
99✔
112
                                    (*vec).push(item);
99✔
113
                                })
99✔
114
                                .len(|ptr| unsafe {
16✔
115
                                    let vec = ptr.get::<Self>();
16✔
116
                                    vec.len()
16✔
117
                                })
16✔
118
                                .as_ptr(|ptr| unsafe {
30✔
119
                                    let vec = ptr.get::<Self>();
30✔
120
                                    PtrConst::new(vec.as_ptr())
30✔
121
                                })
30✔
NEW
122
                                .as_mut_ptr(|ptr| unsafe {
×
NEW
123
                                    let vec = ptr.as_mut::<Self>();
×
NEW
124
                                    PtrMut::new(vec.as_mut_ptr())
×
NEW
125
                                })
×
126
                                .build()
127
                        },
128
                    )
129
                    .t(|| T::SHAPE)
173✔
130
                    .build(),
131
            ))
132
            .build()
133
    };
134
}
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