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

facet-rs / facet / 14931971708

09 May 2025 03:08PM UTC coverage: 55.308%. First build
14931971708

Pull #527

github

web-flow
Merge 10005e18e into a46b975f2
Pull Request #527: Rework type information (Def) — rebased #462

1077 of 1985 new or added lines in 50 files covered. (54.26%)

6669 of 12058 relevant lines covered (55.31%)

73.99 hits per line

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

51.16
/facet-core/src/impls_core/pointer.rs
1
use core::{fmt, hash::Hash};
2

3
use crate::{
4
    Facet, HasherProxy, MarkerTraits, PointerType, Shape, Type, TypeParam, VTableView,
5
    ValuePointerType, ValueVTable,
6
};
7

8
macro_rules! impl_facet_for_pointer {
9
    ($variant:ident: $type:ty => $shape:expr => $vtable_builder:expr => $($ptrkind:tt)+) => {
10
        unsafe impl<'a, T: Facet<'a> + ?Sized> Facet<'a> for $type {
11
            const VTABLE: &'static ValueVTable = &const {
12
                $vtable_builder
13
                    .type_name(|f, opts| {
36✔
14
                        if let Some(opts) = opts.for_children() {
36✔
15
                            write!(f, stringify!($($ptrkind)+, " "))?;
36✔
16
                            (T::VTABLE.type_name)(f, opts)
36✔
17
                        } else {
NEW
18
                            write!(f, stringify!($($ptrkind)+, " ⋯"))
×
19
                        }
20
                    })
36✔
21
                    .build()
22
            };
23

24
            const SHAPE: &'static Shape = &const {
25
                $shape
26
                    .type_params(&[TypeParam {
27
                        name: "T",
28
                        shape: || T::SHAPE,
1✔
29
                    }])
30
                    .ty(Type::Pointer(PointerType::Raw(ValuePointerType {
31
                        mutable: false,
32
                        wide: ::core::mem::size_of::<$($ptrkind)* ()>() != ::core::mem::size_of::<Self>(),
33
                        target: || T::SHAPE,
1✔
34
                    })))
35
                    .build()
36
            };
37
        }
38
    };
39
    (*$mutability:tt) => {
40
        impl_facet_for_pointer!(
41
            Raw: *$mutability T
42
                => Shape::builder_for_sized::<Self>()
NEW
43
                    .inner(|| T::SHAPE)
×
44
                => ValueVTable::builder::<Self>()
45
                    .marker_traits(
46
                        MarkerTraits::EQ
47
                            .union(MarkerTraits::COPY)
48
                            .union(MarkerTraits::UNPIN),
49
                    )
NEW
50
                    .debug(|data, f| fmt::Debug::fmt(data, f))
×
NEW
51
                    .clone_into(|src, dst| unsafe { dst.put(src.clone()) })
×
NEW
52
                    .eq(|left, right| left.cast::<()>().eq(&right.cast::<()>()))
×
NEW
53
                    .partial_ord(|&left, &right| {
×
NEW
54
                        left.cast::<()>().partial_cmp(&right.cast::<()>())
×
NEW
55
                    })
×
NEW
56
                    .ord(|&left, &right| left.cast::<()>().cmp(&right.cast::<()>()))
×
NEW
57
                    .hash(|value, hasher_this, hasher_write_fn| {
×
NEW
58
                        value.hash(&mut unsafe {
×
NEW
59
                            HasherProxy::new(hasher_this, hasher_write_fn)
×
NEW
60
                        })
×
NEW
61
                    })
×
62
                => *$mutability
63
        );
64
    };
65
    (@ $builder:expr => &$($mutability:tt)?) => {
66
        impl_facet_for_pointer!(
67
            Reference: &'a $($mutability)? T
68
                => Shape::builder_for_sized::<Self>()
69
                => {
70
                    let mut builder = $builder;
71

72
                    if T::VTABLE.default_in_place.is_some() {
73
                        builder = builder.default_in_place(|value| {
4✔
74
                            (<VTableView<&$($mutability)? T>>::of_deref().default_in_place().unwrap())(value)
4✔
75
                        });
4✔
76
                    }
77

78
                    if T::VTABLE.debug.is_some() {
79
                        builder = builder.debug(|value, f| {
40✔
80
                            (<VTableView<&$($mutability)? T>>::of_deref().debug().unwrap())(value, f)
40✔
81
                        });
40✔
82
                    }
83

84
                    if T::VTABLE.display.is_some() {
85
                        builder = builder.display(|value, f| {
4✔
86
                            (<VTableView<&$($mutability)? T>>::of_deref().display().unwrap())(value, f)
4✔
87
                        });
4✔
88
                    }
89

90
                    if T::VTABLE.eq.is_some() {
91
                        builder = builder.eq(|a, b| {
5✔
92
                            (<VTableView<&$($mutability)? T>>::of_deref().eq().unwrap())(a, b)
5✔
93
                        });
5✔
94
                    }
95

96
                    if T::VTABLE.ord.is_some() {
NEW
97
                        builder = builder.ord(|a, b| {
×
NEW
98
                            (<VTableView<&$($mutability)? T>>::of_deref().ord().unwrap())(a, b)
×
NEW
99
                        });
×
100
                    }
101

102
                    if T::VTABLE.partial_ord.is_some() {
103
                        builder = builder.partial_ord(|a, b| {
5✔
104
                            (<VTableView<&$($mutability)? T>>::of_deref().partial_ord().unwrap())(a, b)
5✔
105
                        });
5✔
106
                    }
107

108
                    if T::VTABLE.hash.is_some() {
NEW
109
                        builder = builder.hash(|value, state, hasher| {
×
NEW
110
                            (<VTableView<&$($mutability)? T>>::of_deref().hash().unwrap())(value, state, hasher)
×
NEW
111
                        });
×
112
                    }
113

114
                    builder
115
                }
116
                => &$($mutability)?
117
        );
118
    };
119
    (&) => {
120
        impl_facet_for_pointer!(@ ValueVTable::builder::<Self>()
121
            .marker_traits(
122
                MarkerTraits::UNPIN
123
                    .union(MarkerTraits::COPY)
124
            )
NEW
125
            .clone_into(|src, dst| unsafe { dst.put(core::ptr::read(src)) })
×
126
        => &);
127
    };
128
    (&mut) => {
129
        impl_facet_for_pointer!(@ ValueVTable::builder::<Self>()
130
            .marker_traits(
131
                MarkerTraits::UNPIN
132
            )
133
        => &mut
134
        );
135
    };
136
}
137

138
impl_facet_for_pointer!(*const);
139
impl_facet_for_pointer!(*mut);
140
impl_facet_for_pointer!(&mut);
141
impl_facet_for_pointer!(&);
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