facet_core/impls/core/
infallible.rs1use crate::{
2 Def, Facet, HashProxy, OxPtrConst, OxPtrMut, Repr, Shape, ShapeBuilder, StructKind, StructType,
3 Type, TypeOpsIndirect, UserType, VTableIndirect,
4};
5
6const unsafe fn infallible_drop(_ptr: OxPtrMut) {
7 }
9
10const INFALLIBLE_VTABLE: VTableIndirect = VTableIndirect {
12 display: None,
13 debug: Some(infallible_debug),
14 hash: Some(infallible_hash),
15 invariants: None,
16 parse: None,
17 parse_bytes: None,
18 try_from: None,
19 try_into_inner: None,
20 try_borrow_inner: None,
21 partial_eq: Some(infallible_partial_eq),
22 partial_cmp: Some(infallible_partial_cmp),
23 cmp: Some(infallible_cmp),
24};
25
26static INFALLIBLE_TYPE_OPS: TypeOpsIndirect = TypeOpsIndirect {
28 drop_in_place: infallible_drop,
29 default_in_place: None, clone_into: None,
31 is_truthy: None,
32};
33
34unsafe fn infallible_debug(
35 _ox: OxPtrConst,
36 f: &mut core::fmt::Formatter<'_>,
37) -> Option<core::fmt::Result> {
38 Some(f.write_str("Infallible"))
40}
41
42const unsafe fn infallible_hash(_ox: OxPtrConst, _hasher: &mut HashProxy<'_>) -> Option<()> {
43 Some(())
45}
46
47const unsafe fn infallible_partial_eq(_a: OxPtrConst, _b: OxPtrConst) -> Option<bool> {
48 Some(true)
50}
51
52const unsafe fn infallible_partial_cmp(
53 _a: OxPtrConst,
54 _b: OxPtrConst,
55) -> Option<Option<core::cmp::Ordering>> {
56 Some(Some(core::cmp::Ordering::Equal))
58}
59
60const unsafe fn infallible_cmp(_a: OxPtrConst, _b: OxPtrConst) -> Option<core::cmp::Ordering> {
61 Some(core::cmp::Ordering::Equal)
63}
64
65unsafe impl Facet<'_> for core::convert::Infallible {
66 const SHAPE: &'static Shape = &const {
67 ShapeBuilder::for_sized::<core::convert::Infallible>("Infallible")
71 .ty(Type::User(UserType::Struct(StructType {
72 repr: Repr::default(),
73 kind: StructKind::Unit,
74 fields: &[],
75 })))
76 .def(Def::Scalar)
77 .vtable_indirect(&INFALLIBLE_VTABLE)
78 .type_ops_indirect(&INFALLIBLE_TYPE_OPS)
79 .eq()
80 .copy()
81 .send()
82 .sync()
83 .build()
84 };
85}
86
87