inspect_core/
impls_primitives.rs1use crate::{Inspect, InspectCx, Kind, TypeInfo, ValueRef};
4
5impl Inspect for () {
7 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
8 ValueRef::with_type(Kind::Unit, TypeInfo::new("()"))
9 }
10}
11
12impl Inspect for bool {
14 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
15 ValueRef::with_type(Kind::Bool(*self), TypeInfo::new("bool"))
16 }
17}
18
19impl Inspect for char {
21 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
22 ValueRef::with_type(Kind::Char(*self), TypeInfo::new("char"))
23 }
24}
25
26impl Inspect for i8 {
28 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
29 ValueRef::with_type(Kind::I8(*self), TypeInfo::new("i8"))
30 }
31}
32
33impl Inspect for i16 {
34 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
35 ValueRef::with_type(Kind::I16(*self), TypeInfo::new("i16"))
36 }
37}
38
39impl Inspect for i32 {
40 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
41 ValueRef::with_type(Kind::I32(*self), TypeInfo::new("i32"))
42 }
43}
44
45impl Inspect for i64 {
46 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
47 ValueRef::with_type(Kind::I64(*self), TypeInfo::new("i64"))
48 }
49}
50
51impl Inspect for i128 {
52 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
53 ValueRef::with_type(Kind::I128(*self), TypeInfo::new("i128"))
54 }
55}
56
57impl Inspect for isize {
58 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
59 ValueRef::with_type(Kind::Isize(*self), TypeInfo::new("isize"))
60 }
61}
62
63impl Inspect for u8 {
65 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
66 ValueRef::with_type(Kind::U8(*self), TypeInfo::new("u8"))
67 }
68}
69
70impl Inspect for u16 {
71 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
72 ValueRef::with_type(Kind::U16(*self), TypeInfo::new("u16"))
73 }
74}
75
76impl Inspect for u32 {
77 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
78 ValueRef::with_type(Kind::U32(*self), TypeInfo::new("u32"))
79 }
80}
81
82impl Inspect for u64 {
83 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
84 ValueRef::with_type(Kind::U64(*self), TypeInfo::new("u64"))
85 }
86}
87
88impl Inspect for u128 {
89 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
90 ValueRef::with_type(Kind::U128(*self), TypeInfo::new("u128"))
91 }
92}
93
94impl Inspect for usize {
95 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
96 ValueRef::with_type(Kind::Usize(*self), TypeInfo::new("usize"))
97 }
98}
99
100impl Inspect for f32 {
102 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
103 ValueRef::with_type(Kind::F32(*self), TypeInfo::new("f32"))
104 }
105}
106
107impl Inspect for f64 {
108 fn inspect(&self, _cx: &mut InspectCx<'_>) -> ValueRef<'_> {
109 ValueRef::with_type(Kind::F64(*self), TypeInfo::new("f64"))
110 }
111}
112
113impl Inspect for str {
115 fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_> {
116 let truncated = if self.len() > cx.limits().max_string_length {
117 &self[..cx.limits().max_string_length]
118 } else {
119 self
120 };
121 ValueRef::with_type(Kind::Str(truncated.into()), TypeInfo::new("str"))
122 }
123}
124
125#[cfg(feature = "std")]
126impl Inspect for String {
127 fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_> {
128 self.as_str().inspect(cx)
129 }
130}
131
132#[cfg(not(feature = "std"))]
133impl Inspect for alloc::string::String {
134 fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_> {
135 self.as_str().inspect(cx)
136 }
137}
138
139impl Inspect for &[u8] {
141 fn inspect(&self, cx: &mut InspectCx<'_>) -> ValueRef<'_> {
142 let truncated =
143 if self.len() > cx.limits().max_bytes { &self[..cx.limits().max_bytes] } else { self };
144 ValueRef::with_type(Kind::Bytes(truncated), TypeInfo::new("[u8]"))
145 }
146}