facet_core/impls/core/
tuple_empty.rs

1use crate::{
2    Def, Facet, Repr, Shape, ShapeBuilder, StructKind, StructType, Type, TypeOpsDirect, UserType,
3    VTableDirect, type_ops_direct, vtable_direct,
4};
5
6// TypeOps lifted out - shared static (unit has Default but not Clone as Copy type)
7static UNIT_TYPE_OPS: TypeOpsDirect = type_ops_direct!(() => Default);
8
9unsafe impl Facet<'_> for () {
10    const SHAPE: &'static Shape = &const {
11        // () implements Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash
12        // but NOT Display or FromStr
13
14        const VTABLE: VTableDirect = vtable_direct!(() =>
15            Debug,
16            Hash,
17            PartialEq,
18            PartialOrd,
19            Ord,
20        );
21
22        ShapeBuilder::for_sized::<()>("()")
23            .ty(Type::User(UserType::Struct(StructType {
24                repr: Repr::default(),
25                kind: StructKind::Tuple,
26                fields: &[],
27            })))
28            .def(Def::Scalar)
29            .vtable_direct(&VTABLE)
30            .type_ops_direct(&UNIT_TYPE_OPS)
31            .eq()
32            .copy()
33            .send()
34            .sync()
35            .build()
36    };
37}