From 1cfcf71e0428b5fa314b8e82aae2ef5858e8a79a Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 4 May 2023 14:46:17 -0700 Subject: Add an example that depends on `is_ascii` in a `const` --- library/core/src/array/ascii.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'library/core/src/array') 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 [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] -- cgit 1.4.1-3-g733a5