File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1179,13 +1179,39 @@ pub const fn variant_count<T>() -> usize {
1179
1179
intrinsics:: variant_count :: < T > ( )
1180
1180
}
1181
1181
1182
+ /// Provides associated constants for various useful properties of types,
1183
+ /// to give them a canonical form in our code and make them easier to read.
1184
+ ///
1182
1185
/// This is here only to simplify all the ZST checks we need in the library.
1183
1186
/// It's not on a stabilization track right now.
1184
1187
#[ doc( hidden) ]
1185
1188
#[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1186
1189
pub trait SizedTypeProperties : Sized {
1187
1190
/// `true` if this type requires no storage.
1188
1191
/// `false` if its [size](size_of) is greater than zero.
1192
+ ///
1193
+ /// # Examples
1194
+ ///
1195
+ /// ```
1196
+ /// #![feature(sized_type_properties)]
1197
+ /// use core::mem::SizedTypeProperties;
1198
+ ///
1199
+ /// fn do_something_with<T>() {
1200
+ /// if T::IS_ZST {
1201
+ /// // ... special approach ...
1202
+ /// } else {
1203
+ /// // ... the normal thing ...
1204
+ /// }
1205
+ /// }
1206
+ ///
1207
+ /// struct MyUnit;
1208
+ /// assert!(MyUnit::IS_ZST);
1209
+ ///
1210
+ /// // For negative checks, consider using UFCS to emphasize the negation
1211
+ /// assert!(!<i32>::IS_ZST);
1212
+ /// // As it can sometimes hide in the type otherwise
1213
+ /// assert!(!String::IS_ZST);
1214
+ /// ```
1189
1215
#[ doc( hidden) ]
1190
1216
#[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1191
1217
const IS_ZST : bool = size_of :: < Self > ( ) == 0 ;
You can’t perform that action at this time.
0 commit comments