facet_trait/impls/
scalar_impls.rs1use crate::value_vtable;
2use crate::*;
3use std::alloc::Layout;
4use std::borrow::Cow;
5
6unsafe impl Facet for () {
7 const DUMMY: Self = ();
8 const SHAPE: &'static Shape = &const {
9 Shape {
10 layout: Layout::new::<Self>(),
11 def: Def::Scalar(ScalarDef::of::<Self>()),
12 vtable: value_vtable!((), |f, _opts| write!(f, "()")),
13 }
14 };
15}
16
17unsafe impl Facet for String {
18 const DUMMY: Self = String::new();
19 const SHAPE: &'static Shape = &Shape {
20 layout: Layout::new::<Self>(),
21 def: Def::Scalar(ScalarDef::of::<Self>()),
22 vtable: value_vtable!(String, |f, _opts| write!(f, "String")),
23 };
24}
25
26unsafe impl Facet for &str {
27 const DUMMY: Self = "";
28 const SHAPE: &'static Shape = &Shape {
29 layout: Layout::new::<Self>(),
30 def: Def::Scalar(ScalarDef::of::<Self>()),
31 vtable: value_vtable!(&str, |f, _opts| write!(f, "&str")),
32 };
33}
34
35unsafe impl Facet for Cow<'_, str> {
36 const DUMMY: Self = Cow::Borrowed("");
37 const SHAPE: &'static Shape = &Shape {
38 layout: Layout::new::<Self>(),
39 def: Def::Scalar(ScalarDef::of::<Self>()),
40 vtable: value_vtable!(Cow<'_, str>, |f, _opts| write!(f, "Cow<'_, str>")),
41 };
42}
43
44unsafe impl Facet for bool {
45 const DUMMY: Self = false;
46 const SHAPE: &'static Shape = &Shape {
47 layout: Layout::new::<Self>(),
48 def: Def::Scalar(ScalarDef::of::<Self>()),
49 vtable: value_vtable!(bool, |f, _opts| write!(f, "bool")),
50 };
51}
52
53macro_rules! impl_facet_for_integer {
54 ($type:ty) => {
55 unsafe impl Facet for $type {
56 const DUMMY: Self = 0;
57 const SHAPE: &'static Shape = &Shape {
58 layout: Layout::new::<Self>(),
59 def: Def::Scalar(ScalarDef::of::<Self>()),
60 vtable: value_vtable!($type, |f, _opts| write!(f, stringify!($type))),
61 };
62 }
63 };
64}
65
66impl_facet_for_integer!(u8);
67impl_facet_for_integer!(i8);
68impl_facet_for_integer!(u16);
69impl_facet_for_integer!(i16);
70impl_facet_for_integer!(u32);
71impl_facet_for_integer!(i32);
72impl_facet_for_integer!(u64);
73impl_facet_for_integer!(i64);
74impl_facet_for_integer!(u128);
75impl_facet_for_integer!(i128);
76
77macro_rules! impl_facet_for_float {
78 ($type:ty) => {
79 unsafe impl Facet for $type {
80 const DUMMY: Self = 0.0;
81 const SHAPE: &'static Shape = &Shape {
82 layout: Layout::new::<Self>(),
83 def: Def::Scalar(ScalarDef::of::<Self>()),
84 vtable: value_vtable!($type, |f, _opts| write!(f, stringify!($type))),
85 };
86 }
87 };
88}
89
90impl_facet_for_float!(f32);
91impl_facet_for_float!(f64);