facet_core/impls/core/
char_str.rs1use crate::Facet;
2use crate::{
3 Def, OxPtrMut, PrimitiveType, PtrConst, Shape, ShapeBuilder, TextualType, Type, TypeOpsDirect,
4 TypeOpsIndirect, VTableIndirect, type_ops_direct, vtable_direct, vtable_indirect,
5};
6
7static CHAR_TYPE_OPS: TypeOpsDirect = type_ops_direct!(char => Default);
9
10unsafe impl Facet<'_> for char {
11 const SHAPE: &'static Shape = &const {
12 const VTABLE: crate::VTableDirect = vtable_direct!(char =>
13 FromStr,
14 Display,
15 Debug,
16 Hash,
17 PartialEq,
18 PartialOrd,
19 Ord,
20 );
21
22 ShapeBuilder::for_sized::<char>("char")
23 .ty(Type::Primitive(PrimitiveType::Textual(TextualType::Char)))
24 .def(Def::Scalar)
25 .vtable_direct(&VTABLE)
26 .type_ops_direct(&CHAR_TYPE_OPS)
27 .eq()
28 .copy()
29 .send()
30 .sync()
31 .build()
32 };
33}
34
35#[inline(always)]
36unsafe fn str_truthy(value: PtrConst) -> bool {
37 !unsafe { value.get::<str>() }.is_empty()
38}
39
40unsafe fn str_drop(_: OxPtrMut) {}
41
42static STR_TYPE_OPS: TypeOpsIndirect = TypeOpsIndirect {
43 drop_in_place: str_drop,
44 default_in_place: None,
45 clone_into: None,
46 is_truthy: Some(str_truthy),
47};
48
49unsafe impl Facet<'_> for str {
50 const SHAPE: &'static Shape = &const {
51 const VTABLE: VTableIndirect = vtable_indirect!(str =>
52 Display,
53 Debug,
54 Hash,
55 PartialEq,
56 PartialOrd,
57 Ord,
58 );
59
60 ShapeBuilder::for_unsized::<str>("str")
61 .ty(Type::Primitive(PrimitiveType::Textual(TextualType::Str)))
62 .def(Def::Scalar)
63 .vtable_indirect(&VTABLE)
64 .type_ops_indirect(&STR_TYPE_OPS)
65 .eq()
66 .send()
67 .sync()
68 .build()
69 };
70}