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

facet-rs / facet / 19772462056

28 Nov 2025 07:32PM UTC coverage: 60.257% (-0.6%) from 60.902%
19772462056

Pull #956

github

web-flow
Merge e44c5109b into 628cd558c
Pull Request #956: Add DynamicValue support for deserializing into facet_value::Value

369 of 864 new or added lines in 19 files covered. (42.71%)

289 existing lines in 4 files now uncovered.

16722 of 27751 relevant lines covered (60.26%)

153.14 hits per line

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

67.47
/facet-reflect/src/partial/partial_api/ptr.rs
1
use super::*;
2

3
////////////////////////////////////////////////////////////////////////////////////////////////////
4
// Smart pointers
5
////////////////////////////////////////////////////////////////////////////////////////////////////
6
impl Partial<'_> {
7
    /// Pushes a frame to initialize the inner value of a smart pointer (`Box<T>`, `Arc<T>`, etc.)
8
    pub fn begin_smart_ptr(&mut self) -> Result<&mut Self, ReflectError> {
50✔
9
        crate::trace!("begin_smart_ptr()");
10
        self.require_active()?;
50✔
11

12
        // Check that we have a SmartPointer and get necessary data
13
        let (smart_ptr_def, pointee_shape) = {
50✔
14
            let frame = self.frames().last().unwrap();
50✔
15

16
            match &frame.shape.def {
50✔
17
                Def::Pointer(smart_ptr_def) if smart_ptr_def.constructible_from_pointee() => {
50✔
18
                    let pointee_shape = match smart_ptr_def.pointee() {
50✔
19
                        Some(shape) => shape,
50✔
20
                        None => {
NEW
21
                            return Err(ReflectError::OperationFailed {
×
NEW
22
                                shape: frame.shape,
×
NEW
23
                                operation: "Smart pointer must have a pointee shape",
×
UNCOV
24
                            });
×
25
                        }
26
                    };
27
                    (*smart_ptr_def, pointee_shape)
50✔
28
                }
29
                _ => {
NEW
30
                    return Err(ReflectError::OperationFailed {
×
NEW
31
                        shape: frame.shape,
×
NEW
32
                        operation: "push_smart_ptr can only be called on compatible types",
×
NEW
33
                    });
×
34
                }
35
            }
36
        };
37

38
        // Handle re-initialization if the smart pointer is already initialized
39
        self.prepare_for_reinitialization();
50✔
40

41
        let frame = self.frames_mut().last_mut().unwrap();
50✔
42

43
        if pointee_shape.layout.sized_layout().is_ok() {
50✔
44
            // pointee is sized, we can allocate it — for `Arc<T>` we'll be allocating a `T` and
45
            // holding onto it. We'll build a new Arc with it when ending the smart pointer frame.
46

47
            frame.tracker = Tracker::SmartPointer {
26✔
48
                is_initialized: false,
26✔
49
            };
26✔
50

51
            let inner_layout = match pointee_shape.layout.sized_layout() {
26✔
52
                Ok(layout) => layout,
26✔
53
                Err(_) => {
NEW
54
                    return Err(ReflectError::Unsized {
×
NEW
55
                        shape: pointee_shape,
×
NEW
56
                        operation: "begin_smart_ptr, calculating inner value layout",
×
NEW
57
                    });
×
58
                }
59
            };
60
            let inner_ptr: *mut u8 = unsafe { ::alloc::alloc::alloc(inner_layout) };
26✔
61
            let Some(inner_ptr) = NonNull::new(inner_ptr) else {
26✔
NEW
62
                return Err(ReflectError::OperationFailed {
×
NEW
63
                    shape: frame.shape,
×
NEW
64
                    operation: "failed to allocate memory for smart pointer inner value",
×
NEW
65
                });
×
66
            };
67

68
            // Push a new frame for the inner value
69
            self.frames_mut().push(Frame::new(
26✔
70
                PtrUninit::new(inner_ptr),
26✔
71
                pointee_shape,
26✔
72
                FrameOwnership::Owned,
26✔
73
            ));
74
        } else {
75
            // pointee is unsized, we only support a handful of cases there
76
            if pointee_shape == str::SHAPE {
24✔
77
                crate::trace!("Pointee is str");
78

79
                // Allocate space for a String
80
                let string_layout = String::SHAPE
11✔
81
                    .layout
11✔
82
                    .sized_layout()
11✔
83
                    .expect("String must have a sized layout");
11✔
84
                let string_ptr: *mut u8 = unsafe { ::alloc::alloc::alloc(string_layout) };
11✔
85
                let Some(string_ptr) = NonNull::new(string_ptr) else {
11✔
NEW
86
                    return Err(ReflectError::OperationFailed {
×
NEW
87
                        shape: frame.shape,
×
NEW
88
                        operation: "failed to allocate memory for string",
×
NEW
89
                    });
×
90
                };
91
                let frame = Frame::new(
11✔
92
                    PtrUninit::new(string_ptr),
11✔
93
                    String::SHAPE,
94
                    FrameOwnership::Owned,
11✔
95
                );
96
                // Frame::new already sets tracker = Scalar and is_init = false
97
                self.frames_mut().push(frame);
11✔
98
            } else if let Type::Sequence(SequenceType::Slice(_st)) = pointee_shape.ty {
13✔
99
                crate::trace!("Pointee is [{}]", _st.t);
100

101
                // Get the slice builder vtable
102
                let slice_builder_vtable = smart_ptr_def.vtable.slice_builder_vtable.ok_or(
13✔
103
                    ReflectError::OperationFailed {
13✔
104
                        shape: frame.shape,
13✔
105
                        operation: "smart pointer does not support slice building",
13✔
106
                    },
13✔
NEW
107
                )?;
×
108

109
                // Create a new builder
110
                let builder_ptr = (slice_builder_vtable.new_fn)();
13✔
111

112
                // Deallocate the original Arc allocation before replacing with slice builder
113
                if let FrameOwnership::Owned = frame.ownership {
13✔
114
                    if let Ok(layout) = frame.shape.layout.sized_layout() {
13✔
115
                        if layout.size() > 0 {
13✔
116
                            unsafe {
13✔
117
                                ::alloc::alloc::dealloc(frame.data.as_mut_byte_ptr(), layout)
13✔
118
                            };
13✔
119
                        }
13✔
UNCOV
120
                    }
×
UNCOV
121
                }
×
122

123
                // Update the current frame to use the slice builder
124
                frame.data = builder_ptr.as_uninit();
13✔
125
                frame.tracker = Tracker::SmartPointerSlice {
13✔
126
                    vtable: slice_builder_vtable,
13✔
127
                    building_item: false,
13✔
128
                };
13✔
129
                // The slice builder memory is managed by the vtable, not by us
130
                frame.ownership = FrameOwnership::ManagedElsewhere;
13✔
131
            } else {
NEW
132
                return Err(ReflectError::OperationFailed {
×
NEW
133
                    shape: frame.shape,
×
NEW
134
                    operation: "push_smart_ptr can only be called on pointers to supported pointee types",
×
NEW
135
                });
×
136
            }
137
        }
138

139
        Ok(self)
50✔
140
    }
50✔
141
}
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