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

facet-rs / facet / 19992174439

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

Pull #1118

github

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

1138 of 3103 new or added lines in 61 files covered. (36.67%)

540 existing lines in 30 files now uncovered.

24225 of 41240 relevant lines covered (58.74%)

502.5 hits per line

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

93.48
/facet-core/src/impls_std/hashmap.rs
1
use core::hash::BuildHasher;
2
use core::ptr::NonNull;
3
use std::collections::HashMap;
4
use std::hash::RandomState;
5

6
use crate::ptr::{PtrConst, PtrMut};
7

8
use crate::{
9
    Def, Facet, IterVTable, MapDef, MapVTable, Shape, Type, TypeParam, UserType, ValueVTable,
10
    value_vtable,
11
};
12

13
type HashMapIterator<'mem, K, V> = std::collections::hash_map::Iter<'mem, K, V>;
14

15
// TODO: Debug, PartialEq, Eq for HashMap, HashSet
16
unsafe impl<'a, K, V, S> Facet<'a> for HashMap<K, V, S>
17
where
18
    K: Facet<'a> + core::cmp::Eq + core::hash::Hash,
19
    V: Facet<'a>,
20
    S: 'a + Default + BuildHasher,
21
{
22
    const SHAPE: &'static Shape = &const {
23
        Shape {
24
            id: Shape::id_of::<Self>(),
25
            layout: Shape::layout_of::<Self>(),
26
            vtable: ValueVTable {
27
                type_name: |f, opts| {
56✔
28
                    write!(f, "{}<", Self::SHAPE.type_identifier)?;
56✔
29
                    if let Some(opts) = opts.for_children() {
56✔
30
                        K::SHAPE.vtable.type_name()(f, opts)?;
56✔
31
                        write!(f, ", ")?;
56✔
32
                        V::SHAPE.vtable.type_name()(f, opts)?;
56✔
33
                    } else {
NEW
34
                        write!(f, "…")?;
×
35
                    }
36
                    write!(f, ">")
56✔
37
                },
56✔
38
                drop_in_place: ValueVTable::drop_in_place_for::<Self>(),
NEW
39
                default_in_place: Some(|target| unsafe { target.put(Self::default()) }),
×
NEW
40
                ..ValueVTable::new(|_, _| Ok(()))
×
41
            },
42
            ty: Type::User(UserType::Opaque),
43
            def: Def::Map(MapDef {
44
                vtable: &const {
45
                    MapVTable {
46
                        init_in_place_with_capacity_fn: |uninit, capacity| unsafe {
47
                            uninit.put(Self::with_capacity_and_hasher(capacity, S::default()))
67✔
48
                        },
67✔
49
                        insert_fn: |ptr, key, value| unsafe {
50
                            let map = ptr.as_mut::<HashMap<K, V>>();
87✔
51
                            let key = key.read::<K>();
87✔
52
                            let value = value.read::<V>();
87✔
53
                            map.insert(key, value);
87✔
54
                        },
87✔
55
                        len_fn: |ptr| unsafe {
56
                            let map = ptr.get::<HashMap<K, V>>();
5✔
57
                            map.len()
5✔
58
                        },
5✔
59
                        contains_key_fn: |ptr, key| unsafe {
60
                            let map = ptr.get::<HashMap<K, V>>();
12✔
61
                            map.contains_key(key.get())
12✔
62
                        },
12✔
63
                        get_value_ptr_fn: |ptr, key| unsafe {
64
                            let map = ptr.get::<HashMap<K, V>>();
12✔
65
                            map.get(key.get()).map(|v| PtrConst::new(NonNull::from(v)))
12✔
66
                        },
12✔
67
                        iter_vtable: IterVTable {
68
                            init_with_value: Some(|ptr| unsafe {
69
                                let map = ptr.get::<HashMap<K, V>>();
30✔
70
                                let iter: HashMapIterator<'_, K, V> = map.iter();
30✔
71
                                let iter_state = Box::new(iter);
30✔
72
                                PtrMut::new(NonNull::new_unchecked(
30✔
73
                                    Box::into_raw(iter_state) as *mut u8
30✔
74
                                ))
75
                            }),
30✔
76
                            next: |iter_ptr| unsafe {
77
                                let state = iter_ptr.as_mut::<HashMapIterator<'_, K, V>>();
75✔
78
                                state.next().map(|(key, value)| {
75✔
79
                                    (
46✔
80
                                        PtrConst::new(NonNull::from(key)),
46✔
81
                                        PtrConst::new(NonNull::from(value)),
46✔
82
                                    )
46✔
83
                                })
46✔
84
                            },
75✔
85
                            next_back: None,
86
                            size_hint: None,
87
                            dealloc: |iter_ptr| unsafe {
88
                                drop(Box::from_raw(
30✔
89
                                    iter_ptr.as_ptr::<HashMapIterator<'_, K, V>>()
30✔
90
                                        as *mut HashMapIterator<'_, K, V>,
30✔
91
                                ));
92
                            },
30✔
93
                        },
94
                    }
95
                },
96
                k: K::SHAPE,
97
                v: V::SHAPE,
98
            }),
99
            type_identifier: "HashMap",
100
            type_params: &[
101
                TypeParam {
102
                    name: "K",
103
                    shape: K::SHAPE,
104
                },
105
                TypeParam {
106
                    name: "V",
107
                    shape: V::SHAPE,
108
                },
109
            ],
110
            doc: &[],
111
            attributes: &[],
112
            type_tag: None,
113
            inner: None,
114
        }
115
    };
116
}
117

118
unsafe impl Facet<'_> for RandomState {
119
    const SHAPE: &'static Shape = &const {
120
        Shape {
121
            id: Shape::id_of::<Self>(),
122
            layout: Shape::layout_of::<Self>(),
123
            vtable: value_vtable!((), |f, _opts| write!(f, "{}", Self::SHAPE.type_identifier)),
2✔
124
            ty: Type::User(UserType::Opaque),
125
            def: Def::Scalar,
126
            type_identifier: "RandomState",
127
            type_params: &[],
128
            doc: &[],
129
            attributes: &[],
130
            type_tag: None,
131
            inner: None,
132
        }
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