Skip to content

Commit 1cfcf71

Browse files
committed
Add an example that depends on is_ascii in a const
1 parent 370d31b commit 1cfcf71

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/array/ascii.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ use crate::ascii;
44
impl<const N: usize> [u8; N] {
55
/// Converts this array of bytes into a array of ASCII characters,
66
/// or returns `None` if any of the characters is non-ASCII.
7+
///
8+
/// # Examples
9+
///
10+
/// ```
11+
/// #![feature(ascii_char)]
12+
/// #![feature(const_option)]
13+
///
14+
/// const HEX_DIGITS: [std::ascii::Char; 16] =
15+
/// *b"0123456789abcdef".as_ascii().unwrap();
16+
///
17+
/// assert_eq!(HEX_DIGITS[1].as_str(), "1");
18+
/// assert_eq!(HEX_DIGITS[10].as_str(), "a");
19+
/// ```
720
#[unstable(feature = "ascii_char", issue = "110998")]
821
#[must_use]
922
#[inline]

0 commit comments

Comments
 (0)