1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::*;
use core::alloc::Layout;
unsafe impl<T> Facet for [T; 1]
where
T: Facet,
{
const ARCHETYPE: Self = [T::ARCHETYPE; 1];
const SHAPE: &'static Shape = &const {
Shape::builder()
.layout(Layout::new::<[T; 1]>())
.vtable(
&const {
let mut builder = ValueVTable::builder()
.marker_traits(T::SHAPE.vtable.marker_traits)
.type_name(|f, opts| {
if let Some(opts) = opts.for_children() {
write!(f, "[")?;
(T::SHAPE.vtable.type_name)(f, opts)?;
write!(f, "; 1]")
} else {
write!(f, "[⋯; 1]")
}
})
.drop_in_place(|value| unsafe {
core::ptr::drop_in_place(value.as_mut::<[T; 1]>());
});
if T::SHAPE.vtable.debug.is_some() {
builder = builder.debug(|value, f| {
let value = unsafe { value.as_ref::<[T; 1]>() };
write!(f, "[")?;
unsafe {
(T::SHAPE.vtable.debug.unwrap_unchecked())(
OpaqueConst::from_ref(&value[0]),
f,
)?;
}
write!(f, "]")
});
}
if T::SHAPE.vtable.eq.is_some() {
builder = builder.eq(|a, b| {
let a = unsafe { a.as_ref::<[T; 1]>() };
let b = unsafe { b.as_ref::<[T; 1]>() };
unsafe {
(T::SHAPE.vtable.eq.unwrap_unchecked())(
OpaqueConst::from_ref(&a[0]),
OpaqueConst::from_ref(&b[0]),
)
}
});
}
if T::SHAPE.vtable.default_in_place.is_some() {
builder = builder.default_in_place(|target| unsafe {
let t_dip = T::SHAPE.vtable.default_in_place.unwrap_unchecked();
(t_dip)(target.field_uninit(0))
});
}
if T::SHAPE.vtable.clone_into.is_some() {
builder = builder.clone_into(|src, dst| unsafe {
let t_cip = T::SHAPE.vtable.clone_into.unwrap_unchecked();
(t_cip)(
OpaqueConst::from_ref(&src.as_ref::<[T; 1]>()[0]),
dst.field_uninit(0),
)
});
}
if T::SHAPE.vtable.partial_ord.is_some() {
builder = builder.partial_ord(|a, b| {
let a = unsafe { a.as_ref::<[T; 1]>() };
let b = unsafe { b.as_ref::<[T; 1]>() };
unsafe {
(T::SHAPE.vtable.partial_ord.unwrap_unchecked())(
OpaqueConst::from_ref(&a[0]),
OpaqueConst::from_ref(&b[0]),
)
}
});
}
if T::SHAPE.vtable.ord.is_some() {
builder = builder.ord(|a, b| {
let a = unsafe { a.as_ref::<[T; 1]>() };
let b = unsafe { b.as_ref::<[T; 1]>() };
unsafe {
(T::SHAPE.vtable.ord.unwrap_unchecked())(
OpaqueConst::from_ref(&a[0]),
OpaqueConst::from_ref(&b[0]),
)
}
});
}
if T::SHAPE.vtable.hash.is_some() {
builder = builder.hash(|value, state, hasher| {
let value = unsafe { value.as_ref::<[T; 1]>() };
unsafe {
(T::SHAPE.vtable.hash.unwrap_unchecked())(
OpaqueConst::from_ref(&value[0]),
state,
hasher,
)
}
});
}
builder.build()
},
)
.def(Def::List(
ListDef::builder()
.vtable(
&const {
ListVTable::builder()
.init_in_place_with_capacity(|_, _| Err(()))
.push(|_, _| {
panic!("Cannot push to [T; 1]");
})
.len(|_| 1)
.get_item_ptr(|ptr, index| unsafe {
if index >= 1 {
panic!(
"Index out of bounds: the len is 1 but the index is {index}"
);
}
OpaqueConst::new_unchecked(ptr.as_ptr::<[T; 1]>())
})
.build()
},
)
.t(T::SHAPE)
.build(),
))
.build()
};
}