• 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

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

3
use crate::{
4
    ConstTypeId, Def, Facet, KnownSmartPointer, PtrConst, 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)
18
                    .weak(|| <alloc::sync::Weak<T> as Facet>::SHAPE)
×
19
                    .vtable(
20
                        &const {
21
                            SmartPointerVTable::builder()
22
                                .borrow_fn(|opaque| {
×
23
                                    let ptr = Self::as_ptr(unsafe { opaque.get() });
×
NEW
24
                                    PtrConst::new(ptr)
×
25
                                })
26
                                .new_into_fn(|this, ptr| {
×
27
                                    let t = unsafe { ptr.read::<T>() };
×
28
                                    let arc = alloc::sync::Arc::new(t);
×
29
                                    unsafe { this.put(arc) }
×
30
                                })
31
                                .downgrade_fn(|strong, weak| unsafe {
×
32
                                    weak.put(alloc::sync::Arc::downgrade(strong.get::<Self>()))
×
33
                                })
34
                                .build()
35
                        },
36
                    )
37
                    .build(),
38
            ))
39
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
×
40
                f,
×
41
                "Arc"
×
42
            )))
43
            .build()
44
    };
45
}
46

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