Skip to content

Commit ed16dbf

Browse files
committed
Add some more documentation
1 parent f0dc359 commit ed16dbf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

library/core/src/mem/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1179,13 +1179,39 @@ pub const fn variant_count<T>() -> usize {
11791179
intrinsics::variant_count::<T>()
11801180
}
11811181

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+
///
11821185
/// This is here only to simplify all the ZST checks we need in the library.
11831186
/// It's not on a stabilization track right now.
11841187
#[doc(hidden)]
11851188
#[unstable(feature = "sized_type_properties", issue = "none")]
11861189
pub trait SizedTypeProperties: Sized {
11871190
/// `true` if this type requires no storage.
11881191
/// `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+
/// ```
11891215
#[doc(hidden)]
11901216
#[unstable(feature = "sized_type_properties", issue = "none")]
11911217
const IS_ZST: bool = size_of::<Self>() == 0;

0 commit comments

Comments
 (0)