diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-05-04 14:46:17 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-05-04 14:46:17 -0700 |
| commit | 1cfcf71e0428b5fa314b8e82aae2ef5858e8a79a (patch) | |
| tree | 2ad092e2f0ee85266c70e3b951d0732a0ee4efd2 | |
| parent | 370d31b93dba75ceac236d676d6a6df07217ff07 (diff) | |
| download | rust-1cfcf71e0428b5fa314b8e82aae2ef5858e8a79a.tar.gz rust-1cfcf71e0428b5fa314b8e82aae2ef5858e8a79a.zip | |
Add an example that depends on `is_ascii` in a `const`
| -rw-r--r-- | library/core/src/array/ascii.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/core/src/array/ascii.rs b/library/core/src/array/ascii.rs index a942b9e4ae3..3fea9a44049 100644 --- a/library/core/src/array/ascii.rs +++ b/library/core/src/array/ascii.rs @@ -4,6 +4,19 @@ use crate::ascii; impl<const N: usize> [u8; N] { /// Converts this array of bytes into a array of ASCII characters, /// or returns `None` if any of the characters is non-ASCII. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char)] + /// #![feature(const_option)] + /// + /// const HEX_DIGITS: [std::ascii::Char; 16] = + /// *b"0123456789abcdef".as_ascii().unwrap(); + /// + /// assert_eq!(HEX_DIGITS[1].as_str(), "1"); + /// assert_eq!(HEX_DIGITS[10].as_str(), "a"); + /// ``` #[unstable(feature = "ascii_char", issue = "110998")] #[must_use] #[inline] |
