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

facet-rs / facet / 14438741953

14 Apr 2025 06:13AM UTC coverage: 20.628% (-11.0%) from 31.623%
14438741953

Pull #188

github

web-flow
Merge e1c313633 into 046ca7ecc
Pull Request #188: Rewrite facet-reflect for safety

492 of 1057 new or added lines in 44 files covered. (46.55%)

670 existing lines in 18 files now uncovered.

1229 of 5958 relevant lines covered (20.63%)

11.72 hits per line

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

0.0
/facet-core/src/impls_alloc/smartptr.rs
1
use core::alloc::Layout;
2

3
use crate::{
4
    ConstTypeId, Def, Facet, KnownSmartPointer, OpaqueConst, SmartPointerDef, SmartPointerFlags,
5
    SmartPointerVTable, value_vtable,
6
};
7

8
unsafe impl<T: Facet> Facet for alloc::sync::Arc<T> {
9
    const SHAPE: &'static crate::Shape = &const {
10
        crate::Shape::builder()
11
            .id(ConstTypeId::of::<Self>())
12
            .layout(Layout::new::<Self>())
13
            .def(Def::SmartPointer(
14
                SmartPointerDef::builder()
15
                    .pointee(T::SHAPE)
16
                    .flags(SmartPointerFlags::ATOMIC)
17
                    .known(KnownSmartPointer::Arc)
NEW
18
                    .weak(|| <alloc::sync::Weak<T> as Facet>::SHAPE)
×
19
                    .vtable(
20
                        &const {
21
                            SmartPointerVTable::builder()
NEW
22
                                .borrow_fn(|opaque| {
×
NEW
23
                                    let ptr = Self::as_ptr(unsafe { opaque.get() });
×
NEW
24
                                    OpaqueConst::new(ptr)
×
25
                                })
NEW
26
                                .new_into_fn(|this, ptr| {
×
NEW
27
                                    let t = unsafe { ptr.read::<T>() };
×
NEW
28
                                    let arc = alloc::sync::Arc::new(t);
×
NEW
29
                                    unsafe { this.put(arc) }
×
30
                                })
NEW
31
                                .downgrade_fn(|strong, weak| unsafe {
×
NEW
32
                                    weak.put(alloc::sync::Arc::downgrade(strong.get::<Self>()))
×
33
                                })
34
                                .build()
35
                        },
36
                    )
37
                    .build(),
38
            ))
NEW
39
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
×
NEW
40
                f,
×
NEW
41
                "Arc"
×
42
            )))
43
            .build()
44
    };
45
}
46

47
#[cfg(feature = "alloc")]
48
unsafe impl<T: Facet> Facet for alloc::sync::Weak<T> {
49
    const SHAPE: &'static crate::Shape = &const {
50
        crate::Shape::builder()
51
            .id(ConstTypeId::of::<Self>())
52
            .layout(Layout::new::<Self>())
53
            .def(Def::SmartPointer(
54
                SmartPointerDef::builder()
55
                    .pointee(T::SHAPE)
56
                    .flags(SmartPointerFlags::ATOMIC.union(SmartPointerFlags::WEAK))
57
                    .known(KnownSmartPointer::ArcWeak)
NEW
58
                    .strong(|| <alloc::sync::Arc<T> as Facet>::SHAPE)
×
59
                    .vtable(
60
                        &const {
61
                            SmartPointerVTable::builder()
NEW
62
                                .upgrade_into_fn(|weak, strong| unsafe {
×
NEW
63
                                    Some(strong.put(weak.get::<Self>().upgrade()?))
×
64
                                })
65
                                .build()
66
                        },
67
                    )
68
                    .build(),
69
            ))
NEW
70
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
×
NEW
71
                f,
×
NEW
72
                "Arc"
×
73
            )))
74
            .build()
75
    };
76
}
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