Skip to content

Commit 8c1db55

Browse files
committed
Add doc for nonzero const creation
1 parent f6092f2 commit 8c1db55

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/core/src/num/nonzero.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,18 @@ macro_rules! nonzero_integer {
547547
#[doc = concat!("assert_eq!(size_of::<", stringify!($Ty), ">(), size_of::<Option<", stringify!($Ty), ">>());")]
548548
#[doc = concat!("assert_eq!(align_of::<", stringify!($Ty), ">(), align_of::<Option<", stringify!($Ty), ">>());")]
549549
/// ```
550+
///
551+
/// # Const Creation
552+
///
553+
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
554+
/// define a new
555+
#[doc = concat!("`", stringify!($Ty), "`")]
556+
/// at compile time via:
557+
/// ```
558+
#[doc = concat!("use std::num::", stringify!($Ty), ";")]
559+
///
560+
#[doc = concat!("const TEN: ", stringify!($Ty), " = const { ", stringify!($Ty) , r#"::new(10).expect("ten is non-zero") };"#)]
561+
/// ```
550562
///
551563
/// [null pointer optimization]: crate::option#representation
552564
#[$stability]

0 commit comments

Comments
 (0)