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

facet-rs / facet / 20022785804

08 Dec 2025 09:14AM UTC coverage: 58.42% (-0.2%) from 58.6%
20022785804

Pull #1176

github

web-flow
Merge 3e131226b into 24ecc6001
Pull Request #1176: fix: implement untagged enum deserialization in facet-json

65 of 241 new or added lines in 4 files covered. (26.97%)

1479 existing lines in 12 files now uncovered.

24741 of 42350 relevant lines covered (58.42%)

543.04 hits per line

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

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

3
////////////////////////////////////////////////////////////////////////////////////////////////////
4
// Allocation, constructors etc.
5
////////////////////////////////////////////////////////////////////////////////////////////////////
6

7
/// Allocate a Partial that can borrow from input with lifetime 'facet.
8
/// This is the default mode - use this when deserializing from a buffer that outlives the result.
9
impl<'facet> Partial<'facet, true> {
10
    /// Allocates a new [Partial] instance on the heap, with the given shape and type.
11
    ///
12
    /// This creates a borrowing Partial that can hold references with lifetime 'facet.
13
    pub fn alloc<T>() -> Result<Self, ReflectError>
1,362✔
14
    where
1,362✔
15
        T: Facet<'facet> + ?Sized,
1,362✔
16
    {
17
        Self::alloc_shape(T::SHAPE)
1,362✔
18
    }
1,362✔
19

20
    /// Allocates a new [Partial] instance on the heap, with the given shape.
21
    ///
22
    /// This creates a borrowing Partial that can hold references with lifetime 'facet.
23
    pub fn alloc_shape(shape: &'static Shape) -> Result<Self, ReflectError> {
1,508✔
24
        alloc_shape_inner(shape)
1,508✔
25
    }
1,508✔
26
}
27

28
/// Allocate a Partial that cannot borrow - all data must be owned.
29
/// Use this when deserializing from a temporary buffer (e.g., HTTP request body).
30
impl Partial<'static, false> {
31
    /// Allocates a new [Partial] instance on the heap, with the given shape and type.
32
    ///
33
    /// This creates an owned Partial that cannot hold borrowed references.
34
    /// Use this when the input buffer is temporary and won't outlive the result.
35
    pub fn alloc_owned<T>() -> Result<Self, ReflectError>
421✔
36
    where
421✔
37
        T: Facet<'static> + ?Sized,
421✔
38
    {
39
        Self::alloc_shape_owned(T::SHAPE)
421✔
40
    }
421✔
41

42
    /// Allocates a new [Partial] instance on the heap, with the given shape.
43
    ///
44
    /// This creates an owned Partial that cannot hold borrowed references.
45
    pub fn alloc_shape_owned(shape: &'static Shape) -> Result<Self, ReflectError> {
422✔
46
        alloc_shape_inner(shape)
422✔
47
    }
422✔
48
}
49

50
/// Internal helper to allocate a Partial with any BORROW value.
51
/// This is used by the deserializer for untagged enum handling.
NEW
UNCOV
52
pub fn alloc_shape_generic<'facet, const BORROW: bool>(
×
NEW
UNCOV
53
    shape: &'static Shape,
×
NEW
UNCOV
54
) -> Result<Partial<'facet, BORROW>, ReflectError> {
×
NEW
UNCOV
55
    alloc_shape_inner(shape)
×
NEW
UNCOV
56
}
×
57

58
fn alloc_shape_inner<'facet, const BORROW: bool>(
1,930✔
59
    shape: &'static Shape,
1,930✔
60
) -> Result<Partial<'facet, BORROW>, ReflectError> {
1,930✔
61
    crate::trace!(
62
        "alloc_shape({:?}), with layout {:?}",
63
        shape,
64
        shape.layout.sized_layout()
65
    );
66

67
    let data = shape.allocate().map_err(|_| ReflectError::Unsized {
1,930✔
68
        shape,
1✔
69
        operation: "alloc_shape",
70
    })?;
1✔
71

72
    // Preallocate a couple of frames. The cost of allocating 4 frames is
73
    // basically identical to allocating 1 frame, so for every type that
74
    // has at least 1 level of nesting, this saves at least one guaranteed reallocation.
75
    let mut stack = Vec::with_capacity(4);
1,929✔
76
    stack.push(Frame::new(data, shape, FrameOwnership::Owned));
1,929✔
77

78
    Ok(Partial {
1,929✔
79
        mode: FrameMode::Strict { stack },
1,929✔
80
        state: PartialState::Active,
1,929✔
81
        invariant: PhantomData,
1,929✔
82
    })
1,929✔
83
}
1,930✔
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