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

facet-rs / facet / 20071285177

09 Dec 2025 04:44PM UTC coverage: 58.627% (-0.1%) from 58.736%
20071285177

Pull #1206

github

web-flow
Merge 9697560d4 into 1cf12db9a
Pull Request #1206: fix(facet-args): support default = "value" for String and integer fields

81 of 276 new or added lines in 15 files covered. (29.35%)

17 existing lines in 4 files now uncovered.

26243 of 44763 relevant lines covered (58.63%)

633.18 hits per line

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

58.33
/facet-core/src/impls/std/path.rs
1
use crate::{
2
    Def, Facet, PtrConst, Shape, ShapeBuilder, Type, UserType, VTableDirect, VTableIndirect,
3
    vtable_direct, vtable_indirect,
4
};
5

6
/// Try to convert from &str or String to PathBuf
7
///
8
/// # Safety
9
/// `dst` must be valid for writes, `src` must point to valid data of type described by `src_shape`
10
unsafe fn pathbuf_try_from(
1✔
11
    dst: *mut std::path::PathBuf,
1✔
12
    src_shape: &'static Shape,
1✔
13
    src: PtrConst,
1✔
14
) -> Result<(), alloc::string::String> {
1✔
15
    // Check if source is &str
16
    if src_shape.id == <&str as Facet>::SHAPE.id {
1✔
17
        let str_ref: &str = unsafe { src.get::<&str>() };
1✔
18
        unsafe { dst.write(std::path::PathBuf::from(str_ref)) };
1✔
19
        return Ok(());
1✔
NEW
20
    }
×
21

22
    // Check if source is String
NEW
23
    if src_shape.id == <alloc::string::String as Facet>::SHAPE.id {
×
NEW
24
        let string: alloc::string::String = unsafe { src.read::<alloc::string::String>() };
×
NEW
25
        unsafe { dst.write(std::path::PathBuf::from(string)) };
×
NEW
26
        return Ok(());
×
NEW
27
    }
×
28

NEW
29
    Err(alloc::format!(
×
NEW
30
        "cannot convert {} to PathBuf",
×
NEW
31
        src_shape.type_identifier
×
NEW
32
    ))
×
33
}
1✔
34

35
/// Parse a PathBuf from a string
36
///
37
/// # Safety
38
/// `target` must be valid for writes
39
unsafe fn pathbuf_parse(s: &str, target: *mut std::path::PathBuf) -> Result<(), crate::ParseError> {
1✔
40
    // PathBuf::from never fails - any string is a valid path
41
    unsafe { target.write(std::path::PathBuf::from(s)) };
1✔
42
    Ok(())
1✔
43
}
1✔
44

45
unsafe impl Facet<'_> for std::path::PathBuf {
46
    const SHAPE: &'static Shape = &const {
47
        const VTABLE: VTableDirect = vtable_direct!(std::path::PathBuf =>
48
            Debug,
49
            Hash,
50
            PartialEq,
51
            PartialOrd,
52
            Ord,
53
            [parse = pathbuf_parse],
54
            [try_from = pathbuf_try_from],
55
        );
56

57
        ShapeBuilder::for_sized::<std::path::PathBuf>("PathBuf")
58
            .ty(Type::User(UserType::Opaque))
59
            .def(Def::Scalar)
60
            .vtable_direct(&VTABLE)
61
            .eq()
62
            .send()
63
            .sync()
64
            .build()
65
    };
66
}
67

68
unsafe impl Facet<'_> for std::path::Path {
69
    const SHAPE: &'static Shape = &const {
70
        const VTABLE: VTableIndirect = vtable_indirect!(std::path::Path =>
71
            Debug,
72
            Hash,
73
            PartialEq,
74
            PartialOrd,
75
            Ord,
76
        );
77

78
        ShapeBuilder::for_unsized::<std::path::Path>("Path")
79
            .ty(Type::User(UserType::Opaque))
80
            .def(Def::Scalar)
81
            .vtable_indirect(&VTABLE)
82
            .eq()
83
            .send()
84
            .sync()
85
            .build()
86
    };
87
}
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