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

facet-rs / facet / 14459841398

15 Apr 2025 02:20AM UTC coverage: 30.835% (+0.7%) from 30.122%
14459841398

push

github

web-flow
Rename opaque to ptr, closes #221 (#222)

47 of 344 new or added lines in 20 files covered. (13.66%)

1 existing line in 1 file now uncovered.

2032 of 6590 relevant lines covered (30.83%)

25.82 hits per line

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

71.7
/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
            .vtable(
15
                &const {
16
                    let mut builder = ValueVTable::builder()
17
                        .type_name(|f, opts| {
108✔
18
                            if let Some(opts) = opts.for_children() {
216✔
19
                                write!(f, "Vec<")?;
×
20
                                (T::SHAPE.vtable.type_name)(f, opts)?;
108✔
21
                                write!(f, ">")
108✔
22
                            } else {
23
                                write!(f, "Vec<⋯>")
×
24
                            }
25
                        })
26
                        .drop_in_place(|value| unsafe { value.drop_in_place::<Vec<T>>() })
14✔
27
                        .default_in_place(|target| unsafe { target.put(Self::default()) })
17✔
28
                        .clone_into(|src, dst| unsafe { dst.put(src.get::<Vec<T>>()) });
×
29

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

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

68
                    if T::SHAPE.vtable.hash.is_some() {
69
                        builder = builder.hash(|value, hasher_this, hasher_write_fn| unsafe {
70
                            use crate::HasherProxy;
71
                            let vec = value.get::<Vec<T>>();
×
72
                            let t_hash = T::SHAPE.vtable.hash.unwrap_unchecked();
×
73
                            let mut hasher = HasherProxy::new(hasher_this, hasher_write_fn);
×
74
                            vec.len().hash(&mut hasher);
×
75
                            for item in vec {
×
NEW
76
                                (t_hash)(PtrConst::new(item), hasher_this, hasher_write_fn);
×
77
                            }
78
                        });
79
                    }
80

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

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