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

facet-rs / facet / 14439358497

14 Apr 2025 06:53AM UTC coverage: 21.3% (-10.3%) from 31.623%
14439358497

push

github

web-flow
Rewrite facet-reflect for safety (#188)

* Rewrite facet-reflect for safety

* WIP invariants support

* WIP invariants

* WIP invariants

* Invariant validation works!

* Fix derive for enums

* Start documenting new reflect

* Comment out other workspace members for now.

* Get rid of warnings, tests pass again for now

* Update main readme

* Take care of Peek

* Yay no more errors in peek

* Most of Peek is back.

* PeekOption tests

* fix enum test

* Refactor enum field access methods

Replace field name-based access with index-based access and provide
a field_by_name helper. Remove redundant tuple_field method in favor
of a unified field access approach that works for both tuple and struct
variants.

* PeekList tests

* no clippy warnings

* Avoid clippy --all-features locally, which trashes target/

* Add map tests

* Some smart pointer tests

* Avoid cycles with delayed/fns

* Fix doc errors, rename impls to different file paths

* Option Debug

* f64 implements PartialCmp

* Replace as_ref with get in all unsafe blocks.

* When putting into a PokeValueUninit, require : 'mem

cf. #190 / https://github.com/facet-rs/facet/issues/190#issuecomment-2799860033

* Document facet-ansi

* Light ui test harness

* Make sure the facet-ansi tests can pass.

* Port facet-pretty over

* facet-pretty good except indentation, ofc

* Fix doc comment formatting

* Port libc sample test

* Uncomment scalar test

* Re-add smart pointer tests

* WIP HeapVal wrapper

* Wip HeapValue wrapper

* API design is hard okay

* Oh now poke tests are ANGRY

* Still HeapAlloc'ing

* More HeapVal

* whew 4

* Mhh slots are gonna be hard to get right

* well some things are failing BADLY

* no problems huh

* 2 failing

* mhmh

* mh

* I don't get it

* Test tree

* Try out a tree

* Cannot move out of huh, where have I heard that before

* Tree => builder

* New builder API coming along

* there we have it again — an invariant violation

* OMG IT WAS MEMCPY ALL ALONG

* Ah, ... (continued)

518 of 1109 new or added lines in 45 files covered. (46.71%)

642 existing lines in 17 files now uncovered.

1278 of 6000 relevant lines covered (21.3%)

12.01 hits per line

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

63.46
/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| {
2✔
18
                            if let Some(opts) = opts.for_children() {
4✔
19
                                write!(f, "Vec<")?;
×
20
                                (T::SHAPE.vtable.type_name)(f, opts)?;
2✔
21
                                write!(f, ">")
2✔
22
                            } else {
23
                                write!(f, "Vec<⋯>")
×
24
                            }
25
                        })
26
                        .drop_in_place(|value| unsafe { value.drop_in_place::<Vec<T>>() })
1✔
27
                        .default_in_place(|target| unsafe { target.put(Self::default()) })
1✔
NEW
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
                                        OpaqueConst::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
                                    OpaqueConst::new(item_a),
1✔
59
                                    OpaqueConst::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;
NEW
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 {
×
76
                                (t_hash)(OpaqueConst::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 {
×
NEW
97
                            data.put(Self::with_capacity(capacity))
×
98
                        })
99
                        .push(|ptr, item| unsafe {
×
100
                            let vec = ptr.as_mut::<Vec<T>>();
×
101
                            let item = item.read::<T>();
×
102
                            (*vec).push(item);
×
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
                            OpaqueConst::new(vec.as_ptr().add(index))
6✔
117
                        })
118
                        .build()
119
                        },
120
                    )
121
                    .t(T::SHAPE)
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

© 2026 Coveralls, Inc