about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2022-09-24 12:12:41 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2022-09-24 12:12:41 -0700
commited16dbf65e55c54a6cb5eb2596a46a6639428370 (patch)
tree2b42ff1058aeb064f97484a6fd6d2972210f93e1
parentf0dc35927becebf20730117a0bf00840ac1dd4ff (diff)
downloadrust-ed16dbf65e55c54a6cb5eb2596a46a6639428370.tar.gz
rust-ed16dbf65e55c54a6cb5eb2596a46a6639428370.zip
Add some more documentation
-rw-r--r--library/core/src/mem/mod.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index cd92ea24b61..66fca2fd281 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -1179,6 +1179,9 @@ pub const fn variant_count<T>() -> usize {
     intrinsics::variant_count::<T>()
 }
 
+/// Provides associated constants for various useful properties of types,
+/// to give them a canonical form in our code and make them easier to read.
+///
 /// This is here only to simplify all the ZST checks we need in the library.
 /// It's not on a stabilization track right now.
 #[doc(hidden)]
@@ -1186,6 +1189,29 @@ pub const fn variant_count<T>() -> usize {
 pub trait SizedTypeProperties: Sized {
     /// `true` if this type requires no storage.
     /// `false` if its [size](size_of) is greater than zero.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(sized_type_properties)]
+    /// use core::mem::SizedTypeProperties;
+    ///
+    /// fn do_something_with<T>() {
+    ///     if T::IS_ZST {
+    ///         // ... special approach ...
+    ///     } else {
+    ///         // ... the normal thing ...
+    ///     }
+    /// }
+    ///
+    /// struct MyUnit;
+    /// assert!(MyUnit::IS_ZST);
+    ///
+    /// // For negative checks, consider using UFCS to emphasize the negation
+    /// assert!(!<i32>::IS_ZST);
+    /// // As it can sometimes hide in the type otherwise
+    /// assert!(!String::IS_ZST);
+    /// ```
     #[doc(hidden)]
     #[unstable(feature = "sized_type_properties", issue = "none")]
     const IS_ZST: bool = size_of::<Self>() == 0;